I am having three Grids Gridview1,Gridview2,Gridview3 each in three pannels panel1,panel2,panel3
Panel1 is having Gridview1.
First column of Gridview1 has LinkButton and clicking on link button gridview2 will be displayed according to the Gridview1 first column values.
Panel2 is having Gridview2 and a Button with name "NEXT"
When I click on "NEXT" button, I need to get Gridview3 values with GridView1s linkbutton ID.
Protected Sub BtnNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnNext.Click
Panel1.Visible = False
Panel2.Visible = False
Panel3.Visible = True
Me.GridView1.SelectedIndex = Me.GridView1.SelectedValue
Dim index As Integer = GridView1.DataKeys.Item(GridView1.SelectedIndex).Values(0)
Dim sqlDataSourceNestedGrid As SqlDataSource = New SqlDataSource()
sqlDataSourceNestedGrid.ConnectionString = ConfigurationManager.ConnectionStrings("DbConnstr").ConnectionString
sqlDataSourceNestedGrid.SelectCommand = "SELECT j.jobno,S.InwardNo,j.jobref from JobMasteras j INNER JOIN SampleDetails s ON j.jobref=s.InwardNo where SampleMaster.SM_L_SampleMasterReference= '" + index+ "' "
GridView3.DataSource = sqlDataSourceNestedGridGridView3.DataBind()
End Sub
The problem is that when i Click on linkbutton which is inside GridView1, the GridView2 is displaying and when i click on NEXT button then Gridview3 results are dispaying in increment manner for the every click.
How do i get linkbutton selectedindex for GridView1 ?
I tried with GridView1.Rows(0).Cells(0) but it will get only Gridview first row first cell .
Public Property GridView1Index() As String
Get
If (ViewState("_GridView1Index") Is Nothing) Then
ViewState("_GridView1Index") = 0
End If
Return ViewState("_GridView1Index")
End Get
Set(ByVal value As String)
ViewState("_GridView1Index") = value
End Set
End Property
Add this property in your code, onclick of Gridview1 Linkbutton while binding GridView2 assign value in this property.
Protected Sub BtnNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnNext.Click
Panel1.Visible = False
Panel2.Visible = False
Panel3.Visible = True
Dim index As Integer = GridView1.DataKeys.Item(GridView1Index).Values(0)
Dim sqlDataSourceNestedGrid As SqlDataSource = New SqlDataSource()
sqlDataSourceNestedGrid.ConnectionString = ConfigurationManager.ConnectionStrings("DbConnstr").ConnectionString
sqlDataSourceNestedGrid.SelectCommand = "SELECT j.jobno,S.InwardNo,j.jobref from JobMasteras j INNER JOIN SampleDetails s ON j.jobref=s.InwardNo where SampleMaster.SM_L_SampleMasterReference= '" + index+ "' "
GridView3.DataSource = sqlDataSourceNestedGrid
GridView3.DataBind()
End Sub
sameer.khanjit@gmail.com
View Blog Click "Mark as Answer" on the post that helped you.
Try setting the CommandArgument of the LinkButton to the actual value that you need? Use something like this in the LinkButton's definition in your ASPX code:
2)Click on Linkbutton of gridview1, you want to show GRidView2 as per row clicked(linkbutton clicked)
3)On Click of next button you want to bind GridView3 as per row selected in GridView1
For achiving #3 Please maintain rowselection index in property of gridview1 linkbutton click. property should store index in ViewState (For mainitanig state of property on postback) Then on click of next button easily you can get index by using that property.
In my previous post , i have provided property code with viewstate. just you need to copy past that code into your page code behind, assign gridview index on click of linkbutton into property and get that index from property on next button click.
sameer.khanjit@gmail.com
View Blog Click "Mark as Answer" on the post that helped you.
Public Property GridView1Index() As String
Get
If (ViewState("_GridView1Index") Is Nothing) Then
ViewState("_GridView1Index") = 0
End If
Return ViewState("_GridView1Index")
End Get
Set(ByVal value As String)
ViewState("_GridView1Index") = value
End Set
End Property
Dim lnkbtn As LinkButton = DirectCast(sender, LinkButton)
Dim Index As Integer = Convert.ToInt32(lnkbtn.CommandArgument)
GridView1Index = Index ;
And use this index in NEXT button click like
Dim sqlDataSourceNestedGrid As SqlDataSource = New SqlDataSource()
sqlDataSourceNestedGrid.ConnectionString = ConfigurationManager.ConnectionStrings("DbConnstr").ConnectionString
sqlDataSourceNestedGrid.SelectCommand = "SELECT j.jobno,S.InwardNo,j.jobref from JobMasteras j INNER JOIN SampleDetails s ON j.jobref=s.InwardNo where SampleMaster.SM_L_SampleMasterReference= '" + GridView1Index + "' "
GridView3.DataSource = sqlDataSourceNestedGrid
GridView3.DataBind()
sameer.khanjit@gmail.com
View Blog Click "Mark as Answer" on the post that helped you.
Priya621
Member
8 Points
31 Posts
how to get gridviews rowindex for first column
Dec 27, 2012 09:56 AM|LINK
Hi ,
I am having three Grids Gridview1,Gridview2,Gridview3 each in three pannels panel1,panel2,panel3
Panel1 is having Gridview1.
First column of Gridview1 has LinkButton and clicking on link button gridview2 will be displayed according to the Gridview1 first column values.
Panel2 is having Gridview2 and a Button with name "NEXT"
When I click on "NEXT" button, I need to get Gridview3 values with GridView1s linkbutton ID.
Protected Sub BtnNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnNext.Click Panel1.Visible = False Panel2.Visible = False Panel3.Visible = True Me.GridView1.SelectedIndex = Me.GridView1.SelectedValue Dim index As Integer = GridView1.DataKeys.Item(GridView1.SelectedIndex).Values(0) Dim sqlDataSourceNestedGrid As SqlDataSource = New SqlDataSource() sqlDataSourceNestedGrid.ConnectionString = ConfigurationManager.ConnectionStrings("DbConnstr").ConnectionString sqlDataSourceNestedGrid.SelectCommand = "SELECT j.jobno,S.InwardNo,j.jobref from JobMasteras j INNER JOIN SampleDetails s ON j.jobref=s.InwardNo where SampleMaster.SM_L_SampleMasterReference= '" + index+ "' " GridView3.DataSource = sqlDataSourceNestedGrid GridView3.DataBind() End Subsameer_khanj...
Contributor
7060 Points
1378 Posts
Re: how to get gridviews rowindex for first column
Dec 27, 2012 10:08 AM|LINK
Public Property GridView1Index() As String Get If (ViewState("_GridView1Index") Is Nothing) Then ViewState("_GridView1Index") = 0 End If Return ViewState("_GridView1Index") End Get Set(ByVal value As String) ViewState("_GridView1Index") = value End Set End PropertyAdd this property in your code, onclick of Gridview1 Linkbutton while binding GridView2 assign value in this property.
Protected Sub BtnNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnNext.Click Panel1.Visible = False Panel2.Visible = False Panel3.Visible = True Dim index As Integer = GridView1.DataKeys.Item(GridView1Index).Values(0) Dim sqlDataSourceNestedGrid As SqlDataSource = New SqlDataSource() sqlDataSourceNestedGrid.ConnectionString = ConfigurationManager.ConnectionStrings("DbConnstr").ConnectionString sqlDataSourceNestedGrid.SelectCommand = "SELECT j.jobno,S.InwardNo,j.jobref from JobMasteras j INNER JOIN SampleDetails s ON j.jobref=s.InwardNo where SampleMaster.SM_L_SampleMasterReference= '" + index+ "' " GridView3.DataSource = sqlDataSourceNestedGrid GridView3.DataBind() End Subsameer.khanjit@gmail.com
View Blog
Click "Mark as Answer" on the post that helped you.
anurag003iit...
Member
176 Points
111 Posts
Re: how to get gridviews rowindex for first column
Dec 27, 2012 10:12 AM|LINK
not clear what u want
but
for rowindex
http://stackoverflow.com/questions/8699772/row-index-of-linkbutton-in-gridview
and use for loop
for(int i=0;GridView3.Rows.Count;i++)
{
string val1=GridView.Rows[0]["ColumnName"].toString();
}
Priya621
Member
8 Points
31 Posts
Re: how to get gridviews rowindex for first column
Dec 27, 2012 10:34 AM|LINK
Hi sameer_khanjit,
The values for the 0 index are coming .
suppose the Gridview1 has 5 records with first column field as column1 having records 1,2,3,4,5 which is linkbutton.
I need to get values of GridView3 for each GridView1 linkbutton clicks.
how can I get the selectedIndex value ?
paindaasp
Star
12080 Points
2034 Posts
Re: how to get gridviews rowindex for first column
Dec 27, 2012 10:38 AM|LINK
Try setting the CommandArgument of the LinkButton to the actual value that you need? Use something like this in the LinkButton's definition in your ASPX code:
CommandArgument='<%# Eval("nextGVID") %>'Priya621
Member
8 Points
31 Posts
Re: how to get gridviews rowindex for first column
Dec 27, 2012 10:44 AM|LINK
Hi paindaasp,
There is no problem with linkbutton.
Linkbutton selected value of GridView1 has to be taken in "NEXT" button Click which is in Panel2 .
sameer_khanj...
Contributor
7060 Points
1378 Posts
Re: how to get gridviews rowindex for first column
Dec 27, 2012 10:45 AM|LINK
As per my understanding you want to achive
1)Bind GridView1 (showing value in gridview 1)
2)Click on Linkbutton of gridview1, you want to show GRidView2 as per row clicked(linkbutton clicked)
3)On Click of next button you want to bind GridView3 as per row selected in GridView1
For achiving #3 Please maintain rowselection index in property of gridview1 linkbutton click. property should store index in ViewState (For mainitanig state of property on postback) Then on click of next button easily you can get index by using that property.
In my previous post , i have provided property code with viewstate. just you need to copy past that code into your page code behind, assign gridview index on click of linkbutton into property and get that index from property on next button click.
sameer.khanjit@gmail.com
View Blog
Click "Mark as Answer" on the post that helped you.
paindaasp
Star
12080 Points
2034 Posts
Re: how to get gridviews rowindex for first column
Dec 27, 2012 10:58 AM|LINK
Then set the CommandArgument of the LinkButton to the row index:
Then store the index in ViewState or a Session variable, as stated previously.
Priya621
Member
8 Points
31 Posts
Re: how to get gridviews rowindex for first column
Dec 27, 2012 11:04 AM|LINK
hi sameer_khanjit
Actually code in linkbutton_click as
and is CommandArgument='<%#Eval("Id")%>'sameer_khanj...
Contributor
7060 Points
1378 Posts
Re: how to get gridviews rowindex for first column
Dec 27, 2012 11:08 AM|LINK
Public Property GridView1Index() As String Get If (ViewState("_GridView1Index") Is Nothing) Then ViewState("_GridView1Index") = 0 End If Return ViewState("_GridView1Index") End Get Set(ByVal value As String) ViewState("_GridView1Index") = value End Set End PropertyAnd use this index in NEXT button click like
Dim sqlDataSourceNestedGrid As SqlDataSource = New SqlDataSource() sqlDataSourceNestedGrid.ConnectionString = ConfigurationManager.ConnectionStrings("DbConnstr").ConnectionString sqlDataSourceNestedGrid.SelectCommand = "SELECT j.jobno,S.InwardNo,j.jobref from JobMasteras j INNER JOIN SampleDetails s ON j.jobref=s.InwardNo where SampleMaster.SM_L_SampleMasterReference= '" + GridView1Index + "' " GridView3.DataSource = sqlDataSourceNestedGrid GridView3.DataBind()sameer.khanjit@gmail.com
View Blog
Click "Mark as Answer" on the post that helped you.