Monday, March 26, 2012

UpdatePanel (Triggers with controls of the Gridview)

English______________________________________________

hi Everybody...i have a control in my TemplateField (a collum of the gridview) with two controls (lnkDelete and lnkEdit), and it's in a UpdatePanel (ASP.NET AJAX). I wanna that when a user to click, on the edit controls...it'll do a postback... How do I configure mine UpdatePanel (Triggers)?

I'm Sorry, but my english isn't good...tanks you

Here are some sample codes to work asp:UpdatePanel with asp:GridView for your reference.
.ASPX:
<div>
<asp:UpdatePanel ID="UpdatePanelNestedGridView" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" OnRowCommand="GridView1_RowCommand">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkDelete" runat="server" Text="Delete" CommandName="Delete"></asp:LinkButton>
<asp:LinkButton ID="lnkEdit" runat="server" Text="Edit" CommandName="Edit"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="userID" HeaderText="userID" InsertVisible="False" ReadOnly="True"/>
<asp:BoundField DataField="alias" HeaderText="alias" SortExpression="alias" />
<asp:BoundField DataField="pwd" HeaderText="pwd" SortExpression="pwd" />
<asp:BoundField DataField="hasForums" HeaderText="hasForums" SortExpression="hasForums" />
<asp:BoundField DataField="isAdmin" HeaderText="isAdmin" SortExpression="isAdmin" />
<asp:BoundField DataField="isDeleted" HeaderText="isDeleted" SortExpression="isDeleted" />
<asp:BoundField DataField="remark" HeaderText="remark" SortExpression="remark" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:PerformancingConnectionString %>" SelectCommand="SELECT [userID], [alias], [pwd], [hasForums], [isAdmin], [isDeleted], [remark] FROM [Users]"></asp:SqlDataSource>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="GridView1" EventName="RowCommand" />
</Triggers>
</asp:UpdatePanel>
</div>
Behind codes:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if(e.CommandName == "Delete")
{
//Delete a record here
}
else if(e.CommandName == "Edit")
{
//Edit current record here
}
}
Wish the above codes can give you some helps.

No comments:

Post a Comment