For Each gvr As Gridviewrow In Gridview1.Rows
If (CType(gvr.findcontrol("CheckBox1"), CheckBox)).Checked = True Then
Dim uPrimaryid As Integer= gvr.cells("uPrimaryID")
End If
Next gvr
Dim uPrimaryid() As Integer
Dim iCount As Integer = 0
For Each gvr As GridViewRow In Gridview1.Rows
If (CType(gvr.FindControl("CheckBox1"), CheckBox)).Checked = True Then
ReDim uPrimaryid(iCount)
uPrimaryid(iCount) = New Integer
uPrimaryid(iCount) = gvr.Cells("uPrimaryID").Text
iCount += 1
End If
Next gvr
code to get all selected checkbox cell value in uPrimaryid integer array....
For Each gvr As Gridviewrow In Gridview1.Rows
If (CType(gvr.findcontrol("CheckBox1"), CheckBox)).Checked = True Then
Dim uPrimaryid As Integer= gvr.cells("uPrimaryID")
End If
Next gvr
hope this helps./.
this work,but hav some small error.
it should be
For Each gvr As GridViewRow In GridView1.Rows
If (CType(gvr.FindControl("CheckBox1"), CheckBox)).Checked = True Then
Dim uPrimaryid As String = (gvr.Cells(x)).Text
End If
Next gvr
so 2 person give me the correct answer,1 in c# and 1 in VB
1st,go to your Gridview properties. click on the button in the button with something like winamp logo as show in the image below,then double click on the
row command
And this is the code behind :
Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
Dim gvr As GridViewRow
Dim gvDataKey As String
gvr = GridView1.Rows(e.CommandArgument)
gvDataKey = gvr.Cells(X).Text
the X will be the column number of your gridview. and the gvDataKey will be storing the value of that column which the button being click.
I don't know what you've pointed in commandargument property of your button, but my property is null, so this string
gvr = GridView1.Rows(e.CommandArgument) would raise an exception. Most likely that you're expecting there the index of the row, but it is not so.
enghsiang
Member
92 Points
237 Posts
How to get the value in the gridview which the checkbox is checked ????
Jun 22, 2007 07:05 AM|LINK
This is my gridview,which some testing data being show.
i had create the checkbox on everyrow,but now i face another problem
what i want is when i click the Button,i can get the value in the gridview which being checked.
example from the image above,after click on the button,i wan to get the uPrimaryID,which is 19 and 21.
can someone help me pls???
thanks[:)]
get the value in the gridview which the checkbox is checked
vinaymohan
Member
142 Points
46 Posts
Re: How to get the value in the gridview which the checkbox is checked ????
Jun 22, 2007 07:33 AM|LINK
In the click event write the below code
foreach(Gridviewrow gvr in Gridview1.Rows)
{
if(((CheckBox)gvr.findcontrol("CheckBox1")).Checked == true)
{
int uPrimaryid= gvr.cells["uPrimaryID"];
}
}
you will get primaryid
enghsiang
Member
92 Points
237 Posts
Re: How to get the value in the gridview which the checkbox is checked ????
Jun 22, 2007 07:44 AM|LINK
this is the code for C# rite?
sorry forgot to tell that i'm using VB
can someone help me to convert that to vb code?coz this is the 1st time i use VB.
kaushalparik...
All-Star
26568 Points
3692 Posts
MVP
Re: How to get the value in the gridview which the checkbox is checked ????
Jun 22, 2007 07:58 AM|LINK
For Each gvr As Gridviewrow In Gridview1.Rows
If (CType(gvr.findcontrol("CheckBox1"), CheckBox)).Checked = True Then
Dim uPrimaryid As Integer= gvr.cells("uPrimaryID")
End If
Next gvr
hope this helps./.
[KaushaL] || BloG || Twitter
Don't forget to click "Mark as Answer" on the post that helped you.
kaushalparik...
All-Star
26568 Points
3692 Posts
MVP
Re: How to get the value in the gridview which the checkbox is checked ????
Jun 22, 2007 08:09 AM|LINK
Dim uPrimaryid() As Integer
Dim iCount As Integer = 0
For Each gvr As GridViewRow In Gridview1.Rows
If (CType(gvr.FindControl("CheckBox1"), CheckBox)).Checked = True Then
ReDim uPrimaryid(iCount)
uPrimaryid(iCount) = New Integer
uPrimaryid(iCount) = gvr.Cells("uPrimaryID").Text
iCount += 1
End If
Next gvr
code to get all selected checkbox cell value in uPrimaryid integer array....
[KaushaL] || BloG || Twitter
Don't forget to click "Mark as Answer" on the post that helped you.
enghsiang
Member
92 Points
237 Posts
Re: How to get the value in the gridview which the checkbox is checked ????
Jun 22, 2007 08:19 AM|LINK
this work,but hav some small error.
it should be
For Each gvr As GridViewRow In GridView1.Rows
If (CType(gvr.FindControl("CheckBox1"), CheckBox)).Checked = True Then
Dim uPrimaryid As String = (gvr.Cells(x)).Text
End If
Next gvr
so 2 person give me the correct answer,1 in c# and 1 in VB
then which 1 should i mark?
can i mark both???
gretchen
Member
60 Points
119 Posts
Re: How to get the value in the gridview which the checkbox is checked ????
Sep 14, 2007 05:05 PM|LINK
Thanks, kaushalparik27! I put that code to good use!
wazzzuup
Member
527 Points
156 Posts
Re: How to get the value in the gridview which the checkbox is checked ????
Oct 06, 2007 01:31 PM|LINK
and what if I have a button instead of checkbox? how could I know datakey of a row, where my clicked button is located? Any help appreciated
Yes I Am!
enghsiang
Member
92 Points
237 Posts
Re: How to get the value in the gridview which the checkbox is checked ????
Oct 08, 2007 01:40 AM|LINK
Maybe this will help u.
1st,go to your Gridview properties. click on the button in the button with something like winamp logo as show in the image below,then double click on the row command
And this is the code behind :
Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand Dim gvr As GridViewRow Dim gvDataKey As String gvr = GridView1.Rows(e.CommandArgument) gvDataKey = gvr.Cells(X).Textthe X will be the column number of your gridview. and the gvDataKey will be storing the value of that column which the button being click.
is that help?
wazzzuup
Member
527 Points
156 Posts
Re: How to get the value in the gridview which the checkbox is checked ????
Oct 08, 2007 05:30 PM|LINK
I don't know what you've pointed in commandargument property of your button, but my property is null, so this string gvr = GridView1.Rows(e.CommandArgument) would raise an exception. Most likely that you're expecting there the index of the row, but it is not so.
Yes I Am!