删除gridview中的行 [英] Deleting a row in a gridview
问题描述
你好每一个;
我有一个gridview,在点击删除linkButton之后永远不会回发,它只是在重新加载页面或向其添加新行后呈现。我也有一个确认消息用户控件,应该在点击删除后弹出并且不显示。
这是一个代码片段:
hello every one;
i have a gridview that is never postback after hitting delete linkButton, it just renders after reload the page or adding a new row to it. also I've a confirm message user control that should be popped up after hitting delete and does not show up.
this is a code snippet:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
DataSourceID="ObjectDataSource1" ForeColor="#333333" GridLines="None" meta:resourcekey="GridView1Resource1"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnRowEditing="GridView1_RowUpdating">
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<!-- some columns-->
<ItemTemplate>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Edit"
Text="Delete" meta:resourcekey="BoundFieldResource144"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<!--user control-->
<uc5:MessageBoxConfirm runat="server" ID="MessageBoxCon" ButtonNoText="No" ButtonYesText="Yes" />
代码behinde:
the code behinde:
protected void GridView1_RowDeleting(object sender, GridViewEditEventArgs e)
{
try
{
MessageBoxCon.ShowBox(CommonRes.Delete,CommonRes.AreYouSureThatYouWantToDelete, CommonRes.Yes, CommonRes.No);//user control
int count = Convert.ToInt32(e.NewEditIndex);
List<classname> clrList = new List<classname>();
clsList = (List<classname>)Session["SaveList"];
classname clsnm = new classname();
clsnm = clrList.ElementAt(count);
clsList.Remove(clsnm );
Session["SaveList"] = clsList;
}
catch (Exception ex)
{
}
}
protected void MessageBoxConfirm_Confirm(object sender,EventArgs e)
{
}
protected void MessageBoxConfirm_Cancel(object sender, EventArgs e)
{
}
推荐答案
首先,您尚未在标记中定义事件。
参考 - GridView.RowDeleting事件 [ ^ ]。请参阅示例中的定义。
First of all, you have not defined the event in Markup.
Refer - GridView.RowDeleting Event[^]. See how it is defined in the example.
<asp:GridView ID="CustomersGridView" runat="server"
DataSourceID="CustomersSqlDataSource"
AutoGenerateColumns="False"
AutoGenerateDeleteButton="True"
OnRowDeleting="CustomersGridView_RowDeleting"
DataKeyNames="CustomerID,AddressID">
此处它自动显示删除按钮,因此,当你点击它时会自动触发事件。
但是如果你想使用LinkButton,那么你需要以
- 的方式实现
RowCommand
事件(例如 - http://www.codeproject.com/Articles/12666/GridView-Delete-with-Confirmation) OR -
LinkButton点击事件
(例如 - 使用链接按钮从Gridview中删除行单击Asp.net并确认 [ ^ ]) RowCommand
Event (example - http://www.codeproject.com/Articles/12666/GridView-Delete-with-Confirmation) ORLinkButton Click Event
(example - Delete Row from Gridview using Link Button Click in Asp.net with Confirmation[^])
And here it automatically shows Delete button, as a result of that, the event gets fired automatically when you click on that.
But if you want to use LinkButton, then you need to implement differently either with
这篇关于删除gridview中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!