Click here to Skip to main content
15,890,527 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
Hi,

I am showing the values in datalist and in each row i have checkbox, so after loading the page, when when the checkbox is changed i need to do some calculations,
Storing the identity column values in label and made visible false

so can anyone help to find the identity column value at which exact row the checkbox is checked,i would do the calculation by oncheckedchange event...
Posted
Comments
amitkarnik2211 31-Mar-11 8:05am    
I had similar Issue Below solution worked

1. Loop through all the datalist items.
2. Use FindControl method on datalist item to get the checkbox in discussion
3. Check if it is checked or not. In case it is, then use FindControl again to get the hidden label value.

Try!

UPDATE:
Try something like...
C#
int count = dl.Items.Count; 
for (int i = 0; i < count; i++) 
{
  Checkbox chk = dl.Items[i].FindControl("chkID") as Checkbox;
  if(chk.Checked)
  { 
    Label ID = dl.Items[i].FindControl("lblID") as Label; 
    string item = ID.Text; 
    // if more than one is checked, continue the loop and track all the texts. 
    // Like: string selectedItemTexts += ID.Text + ",";
  }
}
 
Share this answer
 
v2
Comments
amitkarnik2211 31-Mar-11 8:04am    
Worked for me Thanks my 5
sathya4260 31-Mar-11 8:58am    
hi i need to get the only the checked event column value
int count = dl.Items.Count;
for (int i = 0; i < count; i++) {
Label ID = dl.Items[i].FindControl("lblID") as Label;
string item = ID.Text;
}

Here as per ur advice we can use condition to get the checked value, but i need only the row by which the checked event happen?
Sandeep Mewara 31-Mar-11 9:48am    
Was in good mood. :)

Updated your code and completed it as what it sounded like you need. Try out (my answer updated.)
sathya4260 31-Mar-11 10:00am    
Its good to see,I need to get only the row value at where the checkbox checked event is happen that is: after loading the datalist, if i click any one checkbox from the list, i need to get that row value and do some calculation and then again bind the datalist,
Sandeep Mewara 31-Mar-11 10:06am    
Good. Now do it. Shared the code even. Enjoy.
LinkButton btn = (LinkButton)sender;
DataListItem item = btn.NamingContainer as DataListItem;
Label lbl = (Label)ProductList.Items[item.ItemIndex].FindControl("lblProductCode");
 
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