Click here to Skip to main content
15,908,264 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all,

I have a Grid View and I fill its contents in the runtime and I need to make a check box infront of each row.

I tried to make a check box field but it didn't appear in the grid.

Can any one help me, please?
thanks
Posted
Updated 10-Jan-11 23:50pm
v3
Comments
Dalek Dave 11-Jan-11 6:12am    
Edited for Readability.

For your question posted as comment to answer1 :

C#
CheckBox chk;
foreach (GridViewRow rowItem in GridView1.Rows)
{
 // FindControl function gets the control placed inside the GridView    control from the specified cell
 // FindControl fucntion accepts string id of the control that you want to access
// type casting of control allows to access the properties of that particular control
// here checkbox control type cast is used to access its properties

 chk = (CheckBox)(rowItem.Cells[0].FindControl("chk1"));
 // chk.checked will access the checkbox state on button click event 
//

   if (chk.Checked)
  {
  }
}


Check this link too

http://programming.top54u.com/post/ASP-Net-C-sharp-GridView-FindControl-Checkbox.aspx[^]
 
Share this answer
 
v2
Comments
Dalek Dave 11-Jan-11 6:42am    
Good Answer!
Anupama Roy 11-Jan-11 6:43am    
Thank you Dalek!
Sandeep Mewara 11-Jan-11 7:21am    
Good Answer! 5!
Anupama Roy 11-Jan-11 7:22am    
Thanks Sandeep!
moon2011 12-Jan-11 6:29am    
hiiii all,
as i asked before, that i have agridview filled in the runtime which contains the name of user, his phone and sooo on
i need now to hold the value of phone column and be sure that the phone number i made a spilt on it because it may contain many numbers and i want to insert the first number only.
i hope that i was enough clear,
any help please?

thanks
Hope this[^] also will help you.
 
Share this answer
 
Comments
moon2011 11-Jan-11 6:06am    
thanks alot.
but now, in the run time i need to check if that checkbox.checked==true
it will call an insert function.
i tried to make that but it didn't see the checkbox.
can anyone help me, please?
thanks
Dalek Dave 11-Jan-11 6:12am    
Good Call.
Kasson 11-Jan-11 6:42am    
Thanks Dalek
THIS[^] will help you towards.
 
Share this answer
 
Comments
Dalek Dave 11-Jan-11 6:12am    
Good Link.
Use split function to get it

C#
string number = "91-2694-234567"


string[] numbers = number.Split('-');


txtCountryCode.Text = numbers[0];
txtCityCode.Text = numbers[1];
txtPhoneNumber.Text = numbers[2];


I hope you know how to read & get it from grid.numbers[0] in above code you can make use.
 
Share this answer
 
v2
Comments
moon2011 12-Jan-11 6:42am    
thanks for your answer, but i meant that i want to take "91" for example from your number in your example to pass it to insert function, how can i make that.
thanks
Anupama Roy 12-Jan-11 6:44am    
numbers[0] will give you 91

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