Click here to Skip to main content
15,911,707 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'd be glad if someone could kindly modify the following code so that GridView becomes click-able. The problem is that the code in question works perfectly in my Windows application under CellMouseClick Event of DataGridView but it doesn't work in the Web application since there's no such event therein. So, under what event can it be made click-able?



VB
Try
        dr = Nothing
        Dim str As String
        str = GridView1.SelectedValue(0).Value
        cmd = New SqlCommand("Select* from ProgramDetails.Subjects where SubjectCode='" & str & "'", cn)
        dr = cmd.ExecuteReader
        While (dr.Read)
            txtIdNumber.Text = dr(0)
            txtSubjectCode.Text = dr(1)
            txtSubjectName.Text = dr(2)
            If dr(3) = "Core" Then
                rbnCore.Checked = True
            Else
                rbnElective.Checked = True
            End If
            txtUserId.Text = dr(4)
            txtPassword.Text = dr(5)
        End While
        dr.Close()
        btnSave.Enabled = False
    Catch ex As Exception
    End Try
Posted
Updated 25-Mar-13 2:40am
v2
Comments
CHill60 25-Mar-13 9:05am    
Have a look at these links and see if they help (not posting as solution in case they are not quite what you need - let me know)
http://aspadvice.com/blogs/joteke/archive/2006/01/07/14576.aspx
http://aspnet.4guysfromrolla.com/articles/100103-1.aspx
Dinesh Kumar Nayak 25-Mar-13 9:25am    
In this case you can't make a cell clickable. You have to make the entire row as clickable.
Akaglo 25-Mar-13 10:03am    
CHill60, I've checked the links but both didn't seem to give the right solution. I'd therefore be happy if you could modify my code to resolve the problem in question. Thank you in advance.

You can unable AutoSelectColumn & write code for event SelectedIndex Change.
So that extra column shown to select grid view row.

You can also use below links to do this without using AutoselectColumn property & make complete row click able. But I never tried this.

http://www.velocityreviews.com/forums/t120857-select-gridview-row-without-using-select-button.html[^]

https://groups.google.com/forum/?hl=en&fromgroups=#!topic/microsoft.public.dotnet.framework.aspnet.webcontrols/6d4pWmz2c10[^]
 
Share this answer
 
Comments
Akaglo 26-Mar-13 5:43am    
I've checked the links. Even though the samples look fine they don't seem to give me exactly what I want. The issue is that I want a code that will enable data on a row to appear in the text boxes when the user clicks on the row in the GridView, to perform update. The code above does exactly this in my Windows application and I want same in the Web application.
You needs to use Templates for edit update & delete

Please use belowlinks

Editable GridView in ASP.NET 2.0[^]

Full-featured Editable GridView Control[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900