悬赏100分 老师布置的ASP.NET题目 应该不难 斑竹和大家都来看看

yamijia 2005-03-23 03:38:53
要求用DATAGRID显示后台数据库里的一张表,DATAGRID里显示的每条记录都能手动输入文本类型的回复,并且能把此文本写入数据库,对此记录回复后此记录自动隐藏. 好象不难 可小弟初学ASP.NET 不知道该怎么做 -_-#
有没有真正的高人能够实际的指点一下,愿意送100分,给个例子也好,小弟还是学生,请各位大大帮忙

人人为我,我为人人



...全文
381 24 打赏 收藏 转发到动态 举报
写回复
用AI写文章
24 条回复
切换为时间正序
请发表友善的回复…
发表回复
owenbeckham 2005-03-24
  • 打赏
  • 举报
回复

// get connection string from web.config
string strConnect = ConfigurationSettings.AppSettings["DsnWroxBooksOleDb"];

// create a SQL statement to select some rows from the database
string strSelect = "SELECT * FROM BookList WHERE ISBN LIKE '%07645437%'";

// create a variable to hold an instance of a DataReader object
OleDbDataReader objDataReader;

try
{
// create a new Connection object using the connection string
OleDbConnection objConnect = new OleDbConnection(strConnect);

// open the connection to the database
objConnect.Open();

// create a new Command using the connection object and select statement
OleDbCommand objCommand = new OleDbCommand(strSelect, objConnect);

// execute the SQL statement against the command to get the DataReader
objDataReader = objCommand.ExecuteReader();
}
catch (Exception objError)
{
// display error details
outError.InnerHtml = "<b>* Error while accessing data</b>.<br />"
+ objError.Message + "<br />" + objError.Source + "<p />";
return; // and stop execution
}

// set the DataSource property and bind the grid
MyDataGrid.DataSource = objDataReader;
MyDataGrid.DataBind();
}

</script>

<!--------------------------------------------------------------------------->

</body>
ziyan0218 2005-03-24
  • 打赏
  • 举报
回复
好好看看MSDN吧
上面的例子足够你用了
gngnandgngn 2005-03-24
  • 打赏
  • 举报
回复
这个。。。。。
你自己去查查资料吧,
看看要就发发 2005-03-24
  • 打赏
  • 举报
回复
你太懒
zhangyong83415 2005-03-24
  • 打赏
  • 举报
回复
ASP:Label Text='<%# DataBinder.Eval(Container.DataItem, "Title") %>' runat="server" />
</ItemTemplate>
<EditItemTemplate>
<ASP:TextBox id="txtTitle" Size="60"
Text='<%# DataBinder.Eval(Container.DataItem, "Title") %>' runat="server" />
这就是核心啦
jiafan123 2005-03-24
  • 打赏
  • 举报
回复
对数据库的增删改查
用到ado。net
先要连接数据库
然后用sql增加修改删除数据库
b/s
还是
c/s
wjcking 2005-03-24
  • 打赏
  • 举报
回复
return; // and stop execution
}

// set the DataSource property and bind the grid
MyDataGrid.DataSource = objDataReader;
MyDataGrid.DataBind();
}

</script>

yamijia 2005-03-23
  • 打赏
  • 举报
回复
to:ShingU(行云流水)

好象没用-_-#
ShingU 2005-03-23
  • 打赏
  • 举报
回复
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspnet_regiis.exe

试试看。
yamijia 2005-03-23
  • 打赏
  • 举报
回复
再请问各位大大一个小问题:
为什么我重装系统以后新建WEB项目的时候提示:指定的WEB服务器运行的不是ASP.NET1.1版本
可是我重装前用的也是这个版本啊,是不是IIS的版本不对?IIS需要什么版本才行?
yamijia 2005-03-23
  • 打赏
  • 举报
回复
我也去网上找了呀,可是没找到-_-#
jacklin_036 2005-03-23
  • 打赏
  • 举报
回复
up
yamijia 2005-03-23
  • 打赏
  • 举报
回复
To:kavencai(天堂里的猫)
我照您的意思去试试看,如果能够解决问题一定给分.
neeao 2005-03-23
  • 打赏
  • 举报
回复
楼主没装msdn???????????
lovelxj 2005-03-23
  • 打赏
  • 举报
回复
多去看看datagrid 的 MSDN
bergkamp_my 2005-03-23
  • 打赏
  • 举报
回复
以后的学生是不是只会复制粘贴了?
stoneyu 2005-03-23
  • 打赏
  • 举报
回复
呵呵..問題比較簡單,在問題表裏設個標誌,自動隱藏.selecteditem,實現選中項.
njuzgj 2005-03-23
  • 打赏
  • 举报
回复
呵呵,这个东西就不用劳斑竹大驾了吧

你到书店随便挑本关于ASP.NET类,只要牵扯数据库就肯定有的:)
kavencai 2005-03-23
  • 打赏
  • 举报
回复
哈哈,一大堆,自己慢慢看吧
kavencai 2005-03-23
  • 打赏
  • 举报
回复
<%@Page Language="C#"%>

<%@Import Namespace="System.Data" %>
<%@Import Namespace="System.Data.OleDb" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head>
<title>Editing Data in a DataGrid Control</title>
</head>
<body bgcolor="#ffffff">
<span class="heading">Editing Data in a DataGrid Control</span><hr />

<div id="outError" runat="server" />

<form runat="server">

<ASP:DataGrid id="MyDataGrid" runat="server"
CellPadding = "2"
EditItemStyle-BackColor="yellow"
DataKeyField="ISBN"
OnEditCommand="DoItemEdit"
OnUpdateCommand="DoItemUpdate"
OnCancelCommand="DoItemCancel"
AutoGenerateColumns="False">

<Columns>

<ASP:BoundColumn DataField="ISBN" HeaderText="ISBN" ReadOnly="True" />

<ASP:TemplateColumn HeaderText="Title">
<ItemTemplate>
<ASP:Label Text='<%# DataBinder.Eval(Container.DataItem, "Title") %>' runat="server" />
</ItemTemplate>
<EditItemTemplate>
<ASP:TextBox id="txtTitle" Size="60"
Text='<%# DataBinder.Eval(Container.DataItem, "Title") %>' runat="server" />
</EditItemTemplate>
</ASP:TemplateColumn>

<ASP:BoundColumn DataField="PublicationDate" HeaderText="Published" />

<ASP:EditCommandColumn
EditText="Edit"
CancelText="Cancel"
UpdateText="Update" />

</Columns>

</ASP:DataGrid>

</form>

<!--------------------------------------------------------------------------->

<script language="C#" runat="server">

void Page_Load(Object sender, EventArgs e)
{
if (!Page.IsPostBack)
BindDataGrid(); // create data set and bind to grid control
}


void DoItemEdit(Object objSource, DataGridCommandEventArgs objArgs)
{
// set the EditItemIndex property of the grid to this item's index
MyDataGrid.EditItemIndex = objArgs.Item.ItemIndex;
BindDataGrid(); // bind the data and display it
}


void DoItemUpdate(Object objSource, DataGridCommandEventArgs objArgs)
{
// get a reference to the title and publication date text boxes
TextBox objTitleCtrl = (TextBox)objArgs.Item.FindControl("txtTitle");
TextBox objPubDateCtrl = (TextBox)objArgs.Item.Cells[2].Controls[0];

// create a suitable SQL statement and execute it
string strSQL = "UPDATE Booklist SET Title='" + objTitleCtrl.Text + "', "
+ "PublicationDate='" + objPubDateCtrl.Text + "' "
+ "WHERE ISBN='" + MyDataGrid.DataKeys[objArgs.Item.ItemIndex] + "'";
ExecuteSQLStatement(strSQL);

// set EditItemIndex property of grid to -1 to switch out of Edit mode
MyDataGrid.EditItemIndex = -1;
BindDataGrid(); // bind the data and display it
}


void DoItemCancel(Object objSource, DataGridCommandEventArgs objArgs)
{
// set EditItemIndex property of grid to -1 to switch out of Edit mode
MyDataGrid.EditItemIndex = -1;
BindDataGrid(); // bind the data and display it
}


void BindDataGrid()
{
// get connection string from web.config
string strConnect = ConfigurationSettings.AppSettings["DsnWroxBooksOleDb"];

// create a SQL statement to select some rows from the database
string strSelect = "SELECT * FROM BookList WHERE ISBN LIKE '%07645437%'";

// create a variable to hold an instance of a DataReader object
OleDbDataReader objDataReader;

try
{
// create a new Connection object using the connection string
OleDbConnection objConnect = new OleDbConnection(strConnect);

// open the connection to the database
objConnect.Open();

// create a new Command using the connection object and select statement
OleDbCommand objCommand = new OleDbCommand(strSelect, objConnect);

// execute the SQL statement against the command to get the DataReader
objDataReader = objCommand.ExecuteReader();
}
catch (Exception objError)
{
// display error details
outError.InnerHtml = "<b>* Error while accessing data</b>.<br />"
+ objError.Message + "<br />" + objError.Source + "<p />";
return; // and stop execution
}

// set the DataSource property and bind the grid
MyDataGrid.DataSource = objDataReader;
MyDataGrid.DataBind();
}

</script>

<!--------------------------------------------------------------------------->

</body>
</html>


加载更多回复(4)

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧