?
Solved

selecting a row in a gridview

Posted on 2008-10-20
2
Medium Priority
?
348 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 2000 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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 …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

762 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