<asp:datagrid id="dgstu" Runat="server" OnDeleteCommand="delete" OnUpdateCommand="update" OnCancelCommand="cancel"
OnEditCommand="Edit" HeaderStyle-Font-Bold="True" HeaderStyle-BackColor="gray" Font-Size="8pt"
PagerStyle-HorizontalAlign="Right" PagerStyle-PageButtonCount="3" CellPadding="3" AutoGenerateColumns="False"
Width="100%" PageSize="10" PagerStyle-Mode="NumericPages" AllowPaging="True" OnPageIndexChanged="changepage">
<itemstyle BackColor="Gainsboro" />
<alternatingitemstyle BackColor="DarkGray" />
<columns>
<asp:templatecolumn HeaderText="学号">
<itemtemplate>
<%#databinder.eval(container.dataitem,"sno")%>
</itemtemplate>
<edititemtemplate>
<asp:label ID="sno" Text='<%#databinder.eval(container.dataitem,"sno")%>' Runat =server Width=90px />
</edititemtemplate>
</asp:templatecolumn>
<asp:templatecolumn HeaderText="姓名">
<itemtemplate>
<%#databinder.eval(container.dataitem,"sname")%>
</itemtemplate>
<edititemtemplate>
<asp:textbox ID="sname" Text='<%#databinder.eval(container.dataitem,"sname")%>' Runat =server Width=60px />
</edititemtemplate>
</asp:templatecolumn>
<asp:templatecolumn HeaderText="班级">
<itemtemplate>
<%#databinder.eval(container.dataitem,"sclass")%>
</itemtemplate>
<edititemtemplate>
<asp:textbox ID="sclass" Text='<%#databinder.eval(container.dataitem,"sclass")%>' Runat =server Width=80px />
</edititemtemplate>
</asp:templatecolumn>
<asp:templatecolumn HeaderText="性别">
<itemtemplate>
<%#databinder.eval(container.dataitem,"ssex")%>
</itemtemplate>
<edititemtemplate>
<asp:textbox ID="ssex" Text='<%#databinder.eval(container.dataitem,"ssex")%>' Runat =server Width=40px />
</edititemtemplate>
</asp:templatecolumn>
<asp:templatecolumn HeaderText="E-mail">
<itemtemplate>
<%#databinder.eval(container.dataitem,"semail")%>
</itemtemplate>
<edititemtemplate>
<asp:textbox ID="semail" Text='<%#databinder.eval(container.dataitem,"semail")%>' Runat =server Width=150px/>
</edititemtemplate>
</asp:templatecolumn>
<asp:templatecolumn HeaderText="修改">
<itemtemplate>
<asp:button CommandName="edit" text=" Edit " Runat="server" />
<asp:button CommandName="delete" text="Delete" Runat="server" />
</itemtemplate>
<edititemtemplate>
<asp:button CommandName="update" text="Update" Runat="server" />
<asp:button CommandName="cancel" text="Cancel" Runat="server" />
</edititemtemplate>
</asp:templatecolumn>
</columns>
</asp:datagrid>

解决方案 »

  1.   

    cm8983(思远) 我的mail:[email protected]
      

  2.   

    你可以使用一个SQL语句更新所有的数据,只要你得到这些值并且为每一行值生成一个Update语句,每一个Update直接使用一个";"隔开,这样在使用SqlCommand的时候可以一次更新,更新以后重新邦定。得到Update的方法:通过DataKey和便利所有(显示)的纪录,生成Sql。
    DataGrid好像不能直接指定组合关键字!
      

  3.   

    后台
    private void DataGrid1_ItemCommand_1(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
    switch (e.CommandName.ToString())
    {
    case "del":
    mysql="delete from c_line where id="+DataGrid1.DataKeys[e.Item.ItemIndex];
    yhsw.execute_mysql(mysql); bind();
    break; case "mdy":
    DataGrid1.EditItemIndex=e.Item.ItemIndex;
    bind();
    break;
                    case "cancel":
    DataGrid1.EditItemIndex=-1;
    bind();
    break;
    case "up":
                          TextBox tb;
      DataGridItem item;
      item=DataGrid1.Items[DataGrid1.EditItemIndex];
          tb=(TextBox)item.Cells[1].FindControl("name");
          mysql="update c_line set l_name='"+tb.Text+"' where id='"+DataGrid1.DataKeys[e.Item.ItemIndex].ToString()+"'";
                          yhsw.execute_mysql(mysql);
      DataGrid1.EditItemIndex=-1;
      bind();
     

      break;

    }

    }前台DATAGRID
    <asp:DataGrid id="DataGrid1" runat="server" Width="100%" AutoGenerateColumns="False" DataKeyField="id"
    AllowPaging="True" BorderStyle="None">
    <HeaderStyle HorizontalAlign="Center"></HeaderStyle>
    <Columns>
    <asp:BoundColumn DataField="id" ReadOnly="True" HeaderText="ID">
    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle"></ItemStyle>
    </asp:BoundColumn>
    <asp:TemplateColumn HeaderText="品牌名称">
    <ItemStyle HorizontalAlign="Center"></ItemStyle>
    <ItemTemplate>
    <asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.l_name") %>'>
    </asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox ID=name runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.l_name") %>'>
    </asp:TextBox>
    </EditItemTemplate>
    </asp:TemplateColumn>
    <asp:TemplateColumn HeaderText="修改">
    <HeaderStyle HorizontalAlign="Center"></HeaderStyle>
    <ItemStyle HorizontalAlign="Center"></ItemStyle>
    <ItemTemplate>
    <FONT face="宋体">
    <asp:LinkButton id="LinkButton1" runat="server" CommandName="mdy">修改</asp:LinkButton>/
    <asp:LinkButton id="LinkButton2" runat="server" CommandName="del">删除</asp:LinkButton></FONT>
    </ItemTemplate>
    <EditItemTemplate>
    <FONT face="宋体">
    <asp:LinkButton id="LinkButton3" runat="server" CommandName="up">更 新</asp:LinkButton>/
    <asp:LinkButton id="LinkButton4" runat="server" CommandName="cancel">取 消</asp:LinkButton></FONT>
    </EditItemTemplate>
    </asp:TemplateColumn>
    </Columns>
    <PagerStyle Mode="NumericPages"></PagerStyle>
    </asp:DataGrid>
      

  4.   

    拿这三个字去Google搜一把,包你要的东西都有!
    “孟宪宗”
      

  5.   

    太快了,写错了拿这几个字去Google搜一把,包你要的东西都有!“孟宪会之精彩世界”