开发者

Gridview Question C#

开发者 https://www.devze.com 2023-03-14 18:09 出处:网络
So my gridview has two columnsBookID and BookName how can i retrieve the value of the BookID based on this event?

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 CommandArgument value and set it in a TemplateField to be the BookId value, then OnRowCommand you can use that value in your event handler.

Something like this should do the trick.

ASPX:

<asp:GridView ID="myGridView" runat="server" onrowcommand="myGridView_RowCommand">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:LinkButton ID="myLinkButton" runat="server" CommandArgument='<%#Eval("BookId") %>'>Do Stuff</asp:LinkButton>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField HeaderText="Id" DataField="BookId" />
        <asp:BoundField HeaderText="Name" DataField="BookName" />
    </Columns>
</asp:GridView>

C# code-behind:

protected void myGridView_RowCommand(object sender, GridViewCommandEventArgs e)
{
    int bookID = Convert.ToInt32(e.CommandArgument);
    // Do Stuff
}

On selecting a specific Tab using the Telerik RadTabStrip

check this post How to change progmatically active Tab in RadTabStrip/RadMultiPage? - TabStrip Forum - ASP.NET Controls

looks to be a matter of setting the Selected property for the TabItem and if you're using a MultiPage you'll also need to set the SelectedIndex of that control

radTabStrip1.Tabs.Item( 2 ).Selected = true;
radMultiPage1.SelectedIndex = 2;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号