how to select a row in gridview in asp.net

D

Dinu

hi

how can we select a row in a gridview with out select column and get
events fired

thanks
 
M

Mark Rae [MVP]

how can we select a row in a gridview with out select column and get
events fired

<asp:GridView ID="MyGridView" runat="server"
OnRowDataBound="MyGridView_RowDataBound"
OnSelectedIndexChanged="MyGridView_SelectedIndexChanged">
....
....
....
</asp:GridView>

protected void MyGridView_RowDataBound(object sender, GridViewRowEventArgs
e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick",
ClientScript.GetPostBackEventReference(MyGridView, "Select$" +
e.Row.RowIndex.ToString()));
e.Row.Style.Add("cursor", "pointer");
}
}

protected void MyGridView_SelectedIndexChanged(object sender, EventArgs e)
{
string strSelectedID = MyGridView.SelectedValue.ToString();
}
 
D

Dinu

<asp:GridView ID="MyGridView" runat="server"
OnRowDataBound="MyGridView_RowDataBound"
OnSelectedIndexChanged="MyGridView_SelectedIndexChanged">
...
...
...
</asp:GridView>

protected void MyGridView_RowDataBound(object sender, GridViewRowEventArgs
e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick",
ClientScript.GetPostBackEventReference(MyGridView, "Select$" +
e.Row.RowIndex.ToString()));
e.Row.Style.Add("cursor", "pointer");
}

}

protected void MyGridView_SelectedIndexChanged(object sender, EventArgs e)
{
string strSelectedID = MyGridView.SelectedValue.ToString();

}

It is not working, the page got hanged (i am using vb.net as code-
behind)

Protected Sub gvwServices_RowDataBound(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.GridViewRowEventArgs) Handles
gvwServices.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.Attributes.Add("onclick",
ClientScript.GetPostBackEventReference(gvwServices, "Select$" +
e.Row.RowIndex.ToString()))
e.Row.Style.Add("cursor", "pointer")
End If
End Sub
 
D

Dinu

On which line does the code hang...?


That certainly shouldn't make any difference...

hi

my page has huge amount of data nearly(12500 records to be fetched
from database) and so it is hanged........if i use paging its working.

Thanks
 
M

Mark Rae [MVP]

my page has huge amount of data nearly(12500 records to be fetched
from database) and so it is hanged........if i use paging its working.

Sorted then... :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top