Solved

selecting a row in a gridview

Posted on 2008-10-20
2
336 Views
Last Modified: 2013-11-07
Okay, I will attempt to make this question a bit more simple.  I have a gridview on a webpage that displays user information. What I am trying to do is allow that person to click on that row and it redirects them to another page to edit that partcular row.
0
Comment
Question by:smitty68521
  • 2
2 Comments
 
LVL 6

Accepted Solution

by:
M3mph15 earned 500 total points
ID: 22765113
Ok first step is to hide the select button column in the gridview by setting it's css-class:
<Columns>
            <asp:CommandField ShowSelectButton="True" ItemStyle-CssClass="HiddenColumn" HeaderStyle-CssClass="HiddenColumn">
                <HeaderStyle CssClass="HiddenColumn"></HeaderStyle>
                <ItemStyle CssClass="HiddenColumn"></ItemStyle>
            </asp:CommandField>
 </Columns>

Then in the code behind we place this code in the RowDataBound event of the gridView:

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
'This removes the use of the Select option
'To select a row jsut click on it
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.Attributes.Add("onmouseover", "this.style.cursor='hand';")
e.Row.Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference(sender, "Select$" + e.Row.RowIndex.ToString))
End If
End Sub
And then you can find which row has been selected via code in the SelectedIndexChanged event of the GridView:
For example maybe you wanted to get the data in Cell 5 to add into the querystring when you redirect to the other page so you know what data to display:
Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged

Dim s As String = GridView1.SelectedRow.Cells(5).Text
'Then redirect user to different page
Response.Redirect("otherPage.aspx?item=" & s
End Sub
Hope this helps.
-M3mph15
0
 
LVL 6

Expert Comment

by:M3mph15
ID: 22765116
oh forgot he code to the HiddenColumn css Class:
<style type="text/css">
.HiddenColumn
{
      display:none;
}
</style>
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question