Solved

selecting a row in a gridview

Posted on 2008-10-20
2
343 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

691 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