473,480 Members | 1,874 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

need to get unique ids of selected checkboxes in datagrid

dear all,
i have a datagrid with checkboxes for selection of rows. and want to
get unique id/ids(job_code) from the selected rows in array etc.
can anyone help.
<asp:datagrid id="dgResults" runat="server" DataKeyField="job_code">
<Columns>
<asp:TemplateColumn>
<ItemStyle Width="30px"></ItemStyle>
<ItemTemplate>
<asp:CheckBox ID="chkCol" Runat="server">
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
-----------
-----------
private void imgSubmit_Click(object sender,
System.Web.UI.ImageClickEventArgs e)
{
int a = 0;
DataGridItemCollection items=dgResults.Items;
for (int i=0; i<items.Count; i++)
{
CheckBox cb= (CheckBox)items[i].FindControl("chkCol");
if ((cb != null) && cb.Checked)
{
a += 1;
// need to get IDs from datagrid for the rows which are
selected with checkbox
}
}
}

thanks in advance

Jun 21 '06 #1
6 1933
first off all, you forgot to paste the rest of the code, cause you are
calling for imgSubmit_Click and inside the DataGrid there's no imgSubmit
object :-/
add to the image tag
CommandName='<%# Eval("job_code") %>'
CommandArgument='<%# Eval("job_code") %>'
OnCommand="imgSubmit_Command"

and add the Protected Sub img_Command(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.CommandEventArgs)
inside you can use e.CommandArgument to get the job_code for that line. And
do the procedure in onCommand instead onClick
--

Bruno Alexandre
(a Portuguese in Københanv, Danmark)
<na********@yahoo.com> escreveu na mensagem
news:11*********************@c74g2000cwc.googlegro ups.com...
dear all,
i have a datagrid with checkboxes for selection of rows. and want to
get unique id/ids(job_code) from the selected rows in array etc.
can anyone help.
<asp:datagrid id="dgResults" runat="server" DataKeyField="job_code">
<Columns>
<asp:TemplateColumn>
<ItemStyle Width="30px"></ItemStyle>
<ItemTemplate>
<asp:CheckBox ID="chkCol" Runat="server">
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
-----------
-----------
private void imgSubmit_Click(object sender,
System.Web.UI.ImageClickEventArgs e)
{
int a = 0;
DataGridItemCollection items=dgResults.Items;
for (int i=0; i<items.Count; i++)
{
CheckBox cb= (CheckBox)items[i].FindControl("chkCol");
if ((cb != null) && cb.Checked)
{
a += 1;
// need to get IDs from datagrid for the rows which are
selected with checkbox
}
}
}

thanks in advance

Jun 21 '06 #2
Dear Bruno,
there is no image tag its simply a button, while copy pasting i did'nt
changed its name
you can re see my code and can help me again thank you again in
advance.

protected void btnapplyto_Click(object sender, EventArgs e)
{
int a = 0;
DataGridItemCollection items = l.Items;
for (int i = 0; i < items.Count; i++)
{
CheckBox cb2 = (CheckBox)items[i].FindControl("cb");
if ((cb2 != null) && cb2.Checked)
{

// need to get ID from 1st datagrid column for this
checkbox

}
a += 1;
}

Jun 21 '06 #3
so you have 2 Datagrids!!!

you never mention that before :-)
because you are not firing any event in the DG that has the checkboxes, you
need to run all of them and what you can do is have the VALUE of the
checkbox bind to the ID of the ROW...

so, whenever you get a checked Checkbox you just see it's value and you have
the row ID

because Checkboxes don't have Value property you can convert it to a
CheckboxList with 1 ListItem, and that you have the value property that you
can use.

--

Bruno Alexandre
(a Portuguese in Københanv, Danmark)
<na********@yahoo.com> escreveu na mensagem
news:11*********************@r2g2000cwb.googlegrou ps.com...
Dear Bruno,
there is no image tag its simply a button, while copy pasting i did'nt
changed its name
you can re see my code and can help me again thank you again in
advance.

protected void btnapplyto_Click(object sender, EventArgs e)
{
int a = 0;
DataGridItemCollection items = l.Items;
for (int i = 0; i < items.Count; i++)
{
CheckBox cb2 = (CheckBox)items[i].FindControl("cb");
if ((cb2 != null) && cb2.Checked)
{

// need to get ID from 1st datagrid column for this
checkbox

}
a += 1;
}

Jun 21 '06 #4
do you really need the checkboxes be in a different DG? can't you just have
1 CheckboxList with all of them? you can provide a DataSource to a CBL...

--

Bruno Alexandre
(a Portuguese in Københanv, Danmark)
<na********@yahoo.com> escreveu na mensagem
news:11*********************@r2g2000cwb.googlegrou ps.com...
Dear Bruno,
there is no image tag its simply a button, while copy pasting i did'nt
changed its name
you can re see my code and can help me again thank you again in
advance.

protected void btnapplyto_Click(object sender, EventArgs e)
{
int a = 0;
DataGridItemCollection items = l.Items;
for (int i = 0; i < items.Count; i++)
{
CheckBox cb2 = (CheckBox)items[i].FindControl("cb");
if ((cb2 != null) && cb2.Checked)
{

// need to get ID from 1st datagrid column for this
checkbox

}
a += 1;
}

Jun 21 '06 #5
Dear Bruno,
again disturbing
there is only one datagrid
protected void btnapplyto_Click(object sender, EventArgs e)
{
int a = 0;
DataGridItemCollection items = l.Items;
for (int i = 0; i < items.Count; i++)
{
CheckBox cb2 = (CheckBox)items[i].FindControl("cb");
if ((cb2 != null) && cb2.Checked)
{

// need to get ID from datagrid column for this
checkbox

}
a += 1;
}


Jun 21 '06 #6
Dear Bruno,
again disturbing
there is only one datagrid
protected void btnapplyto_Click(object sender, EventArgs e)
{
int a = 0;
DataGridItemCollection items = l.Items;
for (int i = 0; i < items.Count; i++)
{
CheckBox cb2 = (CheckBox)items[i].FindControl("cb");
if ((cb2 != null) && cb2.Checked)
{

// need to get ID from datagrid column for this
checkbox

}
a += 1;
}


Jun 21 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1365
by: Colleyville Alan | last post by:
I have been working on a project that uses MS Access to get mutual fund performance and write it to a spreadsheet in a formatted manner. The user inputs the company name, the database looks at the...
2
1700
by: Mortar | last post by:
i have a datagrid with a column of html checkboxes which are created dynamically. The id/name of the checkboxes comes from a value in the database. on a postback, i would like to get all the...
1
234
by: Mike | last post by:
I have a datalist that has checkboxes in it and allows the user to select certian things and be able to vew only the items selected. (like hotmail or yahoo where you can select 1 or all and delete...
3
1574
by: xianxian | last post by:
Hi guys, I'm having trouble getting my Datagrid to display according to Checkboxes checked values. On my Checkboxes, I have 5 values :- 1) Apartment/Condo 2) Executive Condo 3) Detached 4)...
0
950
by: dsmigelski | last post by:
I have a datagrid that I am populating, and on my tab and I have a select/Deselect all checkboxes. The only column in my grid that is readable is the first column and it is a bit field displaying...
3
1792
by: GatorBait | last post by:
Hi all, I'm using a datagrid for the first time and I am running into some problems that I hope someone can help me with. I have a datagrid with 18 rows and 5 columns....column 1 is just text...
18
2236
by: Ed Jay | last post by:
<disclaimer>js newbie</disclaimer> My page has a form comprised of several radio buttons. I want to poll the buttons to determine which button was selected and convert its value to a string. I...
7
2487
by: rn5a | last post by:
The first column of a DataGrid has a CheckBox for all the rows. I want that when users check a CheckBox, the BackColor of that entire row in the DataGrid should change to a different color. To...
10
5177
by: rn5a | last post by:
All the rows in a DataGrid, including the Header, are accompanied with a CheckBox. I want that when the CheckBox in the Header is checked, then all the CheckBoxes should automatically get checked....
0
6908
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7081
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6737
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5336
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4481
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2995
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2984
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
179
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.