|
-
May 3rd, 2010, 08:40 AM
#1
Thread Starter
Frenzied Member
Gridview OnClick question
I have a quick question. In my code now I have setup to go to another page when a row is clicked in my gridview which has worked fine. Now I want to change this where I stay on the same page and hide one panel and show another. But I need the value of a cell saved from the click like I already do. I would really like to just do a postback knowing what row/cell data I clicked on and changing visible panels. I don't want the data in the grid to have to rebind incase it is a big one. Can someone show me the code of how to do this?
Thanks!!!
Code:
Private Sub C1GridView1_RowDataBound(ByVal sender As Object, ByVal e As C1.Web.UI.Controls.C1GridView.C1GridViewRowEventArgs) Handles C1GridView1.RowDataBound
If e.Row.RowType = C1.Web.UI.Controls.C1GridView.C1GridViewRowType.DataRow Then
For intI As Integer = 0 To e.Row.Cells.Count - 1
Dim a As String = e.Row.Cells(0).Text.ToString
e.Row.Cells(intI).Attributes.Add("onclick", "parent.location='Test.aspx?vid=" & a & "'")
Next
End If
-
May 3rd, 2010, 08:46 AM
#2
Re: Gridview OnClick question
Then you need to populate your grid inside the
vb Code:
If Not Page.IsPostBack Then 'Bind your grid End If
And in row Command Normally will do postback. In the Postback check in the row column/row index and get the particular row from Gridview using Gridview.Rows(index) and display the data
In the RowDataBound set the Buttons Command Argument as row index
Please mark you thread resolved using the Thread Tools as shown
-
May 3rd, 2010, 08:55 AM
#3
Thread Starter
Frenzied Member
Re: Gridview OnClick question
But the sqldatasource controls do a databind automatically when I do a post back right? So trying to call it when page.ispostback = false is not the only time right?
-
May 3rd, 2010, 09:07 AM
#4
Re: Gridview OnClick question
Are u using SQLDataSource Control ?
Please mark you thread resolved using the Thread Tools as shown
-
May 3rd, 2010, 09:07 AM
#5
Thread Starter
Frenzied Member
Re: Gridview OnClick question
-
May 4th, 2010, 05:03 PM
#6
Re: Gridview OnClick question
Won't be simple, but I'll describe the basic process:
Start by adding a TemplateField to your GridView. In this TemplateField, place a DIV and in this DIV, lay out the 'template' for your details page. (Textboxes, labels, etc).
Further, set the style on the DIV to be style="display:none;" or style="visibility:hidden;" so that when the page loads and the grid is bound, it's invisible. You can also make it float above everything else so that when it does show up, it will be like a popup.
You also need to actually fill this new DIV with the information, on a per-row basis. So in the RowDataBound event, look at the primary key value as you're doing here:
Dim a As String = e.Row.Cells(0).Text.ToString
Then use it to call the database, get the details out for that specific row, and fill up the textboxes, etc. in your new DIV with it.
And then there's the visibility bit - in the onclick, as you're doing here:
e.Row.Cells(intI).Attributes.Add("onclick"...
have the javascript set the visibility of that DIV.
document.getElementById('divid').style.visibility='visible';
so that when the user clicks, the DIV is toggled visible. Note that the DIV ID for each row needs to be unique.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|