vb datagrid 删除,如何在datagrid标题栏里加入一个连接,在datagrid里显示编辑,删除?

如何在datagrid标题栏里加入一个连接,在datagrid里显示编辑,删除? - 故障解答 - 电脑教程网

如何在datagrid标题栏里加入一个连接,在datagrid里显示编辑,删除?

日期:2006-11-21   荐:
如何在datagrid标题栏里加入一个连接,在datagrid里显示编辑,删除?谢谢,希望有个例子如何在datagrid标题栏里加入一个连接,在datagrid里显示编辑,删除-----------------------------标题栏里面加入链接,怎么实现“编辑,删除”,顶多实现一个“插入”请说清楚你的意思。是不是在每一行里面?你应该是在DataGrid中每一行显示添加,修改,删除等按钮吧:aspx中代码:---------------------------<asp:datagrid id="DataGrid1" runat="server" Width="60%" OnDeleteCommand="CatGrid_Delete" OnUpdateCommand="CatGrid_Update"OnCancelCommand="CatGrid_Cancel" OnEditCommand="CatGrid_Edit" DataKeyField="CategoryID" AutoGenerateColumns="False"><Columns><asp:EditCommandColumn ItemStyle-Width="25px" EditText="<img border =0 alt ='Edit' src="http://00000000.net.cn/200606/200606000/images/edit.gif">"CancelText="<img border =0 src="http://00000000.net.cn/200606/200606000/images/cancel.gif> UpdateText<img border 0 srcimages/ok.gif">"></asp:EditCommandColumn><asp:ButtonColumn ItemStyle-Width="25px" Text="<img border =0 alt ='Delete' src="http://00000000.net.cn/200606/200606000/images/delete.gif">"CommandName="delete"></asp:ButtonColumn><asp:BoundColumn HeaderText="ID" ItemStyle-Width="30px" DataField="CategoryID"></asp:BoundColumn><asp:TemplateColumn HeaderText="类别名称" ItemStyle-Width="200px"><ItemTemplate><asp:Label Runat="server" text='<%#DataBinder.Eval(Container.DataItem,"CategoryName")%>'></asp:Label></ItemTemplate><EditItemTemplate><asp:TextBox ID="EditCatName" Runat="server" Width="200px" Text='<%#DataBinder.Eval(Container.DataItem,"CategoryName")%>'></asp:TextBox></EditItemTemplate></asp:TemplateColumn></Columns></asp:datagrid>在aspx.cs中对应的后台代码:----------------------------------------------------------------------protected void CatGrid_Edit(object sender,DataGridCommandEventArgs e){DataGrid1.EditItemIndex =e.Item.ItemIndex ;BindGrid();}protected void CatGrid_Cancel(object sender,DataGridCommandEventArgs e){DataGrid1.EditItemIndex=-1;BindGrid();}protected void CatGrid_Update(object sender,DataGridCommandEventArgs e){string CatgoryName=((TextBox)e.Item.FindControl ("EditCatName")).Text ;int categoryID=int.Parse (DataGrid1.DataKeys[e.Item.ItemIndex].ToString().Trim () ); UpdateRecord1(CatgoryName,categoryID);DataGrid1.EditItemIndex =-1;BindGrid(); }protected void CatGrid_Delete(object sender,DataGridCommandEventArgs e){int categoryID=int.Parse (DataGrid1.DataKeys[e.Item.ItemIndex].ToString().Trim () ); DeleteRecord1(categoryID);DataGrid1.EditItemIndex =-1;BindGrid();}http://xml.sz.luohuedu.net/xml/ShowDetail.asp?id=8ADE535F-AD40-4DE3-A962-A64B4FAF12C4不好意思,不要标题连接了,只要在datagrid里显示编辑,删除?private void DataGrid_list_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e){int i=e.Item.ItemIndex;i ;if (i!=0){e.Item.Cells[0].Text=i.ToString();}}这个例子是设置e.Item.Cells[0].Text,你把这个Text设成一个教本不就行了吗,这个连接中可以包括你要删除的记录ID
标签: