views:

77

answers:

1

hai pupils

I am doing a project on online education. In my project i display the trainees/trainers in in a gridview. If i select any data from the gridview it has to be dispalyed in the label kept below. How can i do this?

Thanks in advance for those who answers.

+2  A: 

Use asp:LinkButton to show data in each column. Set commandArgument as the data. set same comandname and handle rowcommand in gridview rowcommand event.

try the following:

in aspx page:

 <asp:GridView ID="GridView1" OnRowCommand="GridView1_RowCommand" runat="server">
                <Columns>
                    <asp:TemplateField HeaderText="CategoryID">
                        <ItemTemplate>
                            <asp:LinkButton ID="lnkID" runat="server" CommandName="sel" CommandArgument='<%# DataBinder.Eval(Container,"DataItem.CategoryID") %>'
                                Text='<%# DataBinder.Eval(Container,"DataItem.CategoryID") %>'></asp:LinkButton>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="CategoryName">
                        <ItemTemplate>
                            <asp:LinkButton ID="lnkName" runat="server" CommandName="sel" CommandArgument='<%# DataBinder.Eval(Container,"DataItem.CategoryName") %>'
                                Text='<%# DataBinder.Eval(Container,"DataItem.CategoryName") %>'></asp:LinkButton>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
           <asp:Label ID="lblCat" runat="server"></asp:Label>

in aspx.cs page:

protected  void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "sel")
        {
            lblCat.Text = e.CommandArgument;
        }
    }
Himadri
thank you sir......,this might be useful to me........,
If it helps please mark as answer
Himadri