So my gridview has two columns BookID and BookName how can i retrieve the value of the BookID based on this event?
protected void myGridView_RowCommand(object sender, GridViewCommandEventArgs e)
The Other question I had is, my application has thee Tabs (Using Telerik) when I am in the fourth tab which is where I have my gridview and I click on any button, it posts back and sends me to the first tab.. how can I control this?
Thank you very much 🙂
ASP CODE
<asp:GridView ID="myGridView" ShowFooter="true" ShowHeader="true" CaptionAlign="Left"
runat="server" ForeColor="Black" CellPadding="4" AutoGenerateColumns="False"
CssClass="Grid" Width="100%" GridLines="None" OnRowCommand="myGridView_RowCommand"
AllowPaging="True" AllowSorting="true" OnPageIndexChanging="myGridView_PageIndexChanging" PageSize="50" OnSorting="myGridView_Sorting" >
<Columns>
<asp:TemplateField HeaderText="ID">
<ItemTemplate>
<asp:Label runat="server" ID="lblBookID" Text='<%#DataBinder.Eval(Container.DataItem,"ID")%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="name" HeaderText="Book Name" SortExpression="Name" />
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="Delete" Text="Remove" CommandArgument='<%# Eval("ID") %>'
CommandName="RemoveItem" CssClass="Button" runat="server" OnClientClick="javascript:return confirm('Sure you dont need this book.?');" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
No Books found
</EmptyDataTemplate>
<RowStyle CssClass="RowStyle" />
<HeaderStyle CssClass="HeaderStyle" ForeColor="White" HorizontalAlign="Center" />
<AlternatingRowStyle CssClass="AlternatingRowStyle" />
<FooterStyle CssClass="FooterStyle" />
</asp:GridView>
If you utilize the
CommandArgumentvalue and set it in aTemplateFieldto be theBookIdvalue, thenOnRowCommandyou can use that value in your event handler.Something like this should do the trick.
ASPX:
C# code-behind:
On selecting a specific Tab using the Telerik
RadTabStripcheck this post How to change progmatically active Tab in RadTabStrip/RadMultiPage? – TabStrip Forum – ASP.NET Controls
looks to be a matter of setting the
Selectedproperty for theTabItemand if you’re using aMultiPageyou’ll also need to set theSelectedIndexof that control