G.S Bhangal
G.S Bhangal

Reputation: 3280

select a particular row of a gridview, the gridview is in web user control

I have a grid view which is in webuser control and I want to select them, so that I can edit any particular row.

The web user control's (.ascx) is:

<div class="project_data">
    <asp:GridView runat="server" ID="grvBranches" GridLines="None" CellPadding="5" OnRowDataBound="grvBranches_RowDataBound">
        <SelectedRowStyle BackColor="#d8d8d8" />
        <HeaderStyle BackColor="#d8d8d8" />
    </asp:GridView>
</div>

and on the .ascs.cs page

 protected void Page_Load(object sender, EventArgs e)
        {
            int.TryParse(OrganizationID, out OrgId);
            //if (!(Page.IsPostBack))
            {

                grvBranches.DataSource = //datasource;
                grvBranches.DataBind();
            }
        }

and on the .aspx.cs page I have added this control into the placeholder. and I want to select any particular so that I can edit that row.

Thanks. Gurbax

Upvotes: 0

Views: 858

Answers (1)

Pankaj Kumar
Pankaj Kumar

Reputation: 1768

you can refrence jquery in your page that contains the UserControl and then you can do this either in the containing page or the user control iteself

Example Code

<script type="text/javascript">
            $(document).ready(function () {
                //This will select the 2nd row specified by tr:nth-child selector
                //and then the tablecells specified by children() and first column
                //specified by eq(0) and get its value
                $('table[id$="GridView1"] tr:nth-child(2)').children().eq(0).Text();
            });
        </script>

After selecting the row you can any manipulation you want using jquery.

Hope it helps

Upvotes: 1

Related Questions