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

解决方案 »

  1.   

    不明“DATAGRID里显示的每条记录都能手动输入文本类型的回复”
      

  2.   

    <%@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>
      

  3.   

    呵呵,这个东西就不用劳斑竹大驾了吧你到书店随便挑本关于ASP.NET类,只要牵扯数据库就肯定有的:)
      

  4.   

    呵呵..問題比較簡單,在問題表裏設個標誌,自動隱藏.selecteditem,實現選中項.
      

  5.   

    多去看看datagrid  的 MSDN
      

  6.   

    楼主没装msdn???????????
      

  7.   

    To:kavencai(天堂里的猫)
        我照您的意思去试试看,如果能够解决问题一定给分.
      

  8.   

    再请问各位大大一个小问题:
    为什么我重装系统以后新建WEB项目的时候提示:指定的WEB服务器运行的不是ASP.NET1.1版本
    可是我重装前用的也是这个版本啊,是不是IIS的版本不对?IIS需要什么版本才行?
      

  9.   

    C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspnet_regiis.exe试试看。
      

  10.   

    to:ShingU(行云流水) 好象没用-_-#
      

  11.   

    好好看看MSDN吧
    上面的例子足够你用了
      

  12.   


        // 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>
      

  13.   

    return;   //  and stop execution
        }    // set the DataSource property and bind the grid
        MyDataGrid.DataSource = objDataReader;
        MyDataGrid.DataBind();
      }</script>
      

  14.   

    对数据库的增删改查
    用到ado。net
    先要连接数据库
    然后用sql增加修改删除数据库
    b/s
    还是
    c/s
      

  15.   

    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" />
       这就是核心啦