select row in gridview bind to datatable

Asked By ali
27-Feb-10 07:51 AM
Earn up to 0 extra points for answering this tough question.
i have a gridview bind to data table
how to select a row from gridview

help me,thanks

  re: select row in gridview bind to datatable

Venkat K replied to ali
27-Feb-10 09:55 AM

The key event to note is the OnRowDataBound, use the following code to create SELECT functionality on the row.

protected void PeopleGridView_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes["onmouseover"] = "this.style.cursor='hand';this.style.textDecoration='underline';";
            e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';";

            e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.PeopleGridView, "Select$" + e.Row.RowIndex);
        }
    }

Thanks,

  re: select row in gridview bind to datatable

Lalit M. replied to ali
27-Feb-10 01:03 PM
Using CSS & HTML Select Row command sample code


<asp:GridView ID="GridView1"
              runat="server"
              CellPadding="2"
              AutoGenerateColumns="False" Width="500px">
    <Columns>

        <asp:BoundField DataField="ProductID" HeaderText="ProductID">
            <HeaderStyle HorizontalAlign="Left" />
        </asp:BoundField>

        <asp:BoundField DataField="ProductName" HeaderText="Product Name">
            <HeaderStyle HorizontalAlign="Left" Width="200px" />
        </asp:BoundField>

        <asp:BoundField DataField="UnitsInStock" HeaderText="Units In Stock">
            <HeaderStyle HorizontalAlign="Left" />
            <ItemStyle HorizontalAlign="Center" />
        </asp:BoundField>

        <asp:BoundField DataField="UnitPrice" HeaderText="Price Per Unit">
            <HeaderStyle HorizontalAlign="Left" />
            <ItemStyle HorizontalAlign="Center" />
        </asp:BoundField>

        <asp:CommandField HeaderText="Select" ShowHeader="True" ShowSelectButton="True">
            <HeaderStyle HorizontalAlign="Left" />
        </asp:CommandField>

    </Columns>
    <SelectedRowStyle BackColor="#FFFFBB" Font-Bold="True" />
</asp:GridView>
Another sample code here   & also here

  re: re: select row in gridview bind to datatable

ali replied to Lalit M.
27-Feb-10 02:53 PM
hi Venkat K & Lalit M.

thanks

but i have problem this code ,first time work very good,but next time not work
Create New Account