Solved

selecting a row in a gridview

Posted on 2008-10-20
2
332 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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 …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now