<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>
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>
解决方案 »
- 如何去掉 网站 项目的虚拟目录
- dal的问题
- 真郁闷。模仿别人写法出错。。后台代码添加控件。
- asp.net中上一篇下一篇的效果如何实现
- *****自己写的一个分类管理,但是总是不能在点击按钮的时候获得TreeView的NodeData.我的环境是.Net1.1请大家帮忙看看。*****分不多,先谢
- 关于在DataGrid中使用DropDownlist的一系列问题
- (小女子跪求)哪里有讲解 web群集 ,web 服务器群集的书籍???
- 急!!!!!对于不返回任何键列信息的 SelectCommand 不支持 UpdateCommand 的动态 SQL 生成
- 如何实现显示在线人员的功能?(象QQ那样)能真实的显示在线用户,我自己写了一些,可是关闭页面不能及时的反映,Application做的!
- 如何在datagrid里删除一条记录
- 请教,如何实现多文件上传?我打算这样,比如要上传两个文件,利用数据库将要上传文件地址依次存入,然后再取出来,按一次上传按钮,做一
- “并非所有的代码路径都返回值”错误,
DataGrid好像不能直接指定组合关键字!
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>
“孟宪宗”