GridView & CheckBox
-
Hello, Ive got a problem with Gridview! I want access to column's data that is checked. and I dont know why this code doesnt work. The value of "chbxRmove.Checked" always is False even when the column is checked !!! :(( plz help me.
foreach (GridViewRowgridRowinthis.GridView1.Rows) { CheckBoxchbxRmove = (CheckBox)gridRow.FindControl("chkSelect"); if (chbxRmove.Checked) { //Row Index } }
-
Hello, Ive got a problem with Gridview! I want access to column's data that is checked. and I dont know why this code doesnt work. The value of "chbxRmove.Checked" always is False even when the column is checked !!! :(( plz help me.
foreach (GridViewRowgridRowinthis.GridView1.Rows) { CheckBoxchbxRmove = (CheckBox)gridRow.FindControl("chkSelect"); if (chbxRmove.Checked) { //Row Index } }
Probably checkbox is losing state on load event of Page,check it carefully. By the way,if you had problems with internet connection then delete one post of your same question.
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com
-
Hello, Ive got a problem with Gridview! I want access to column's data that is checked. and I dont know why this code doesnt work. The value of "chbxRmove.Checked" always is False even when the column is checked !!! :(( plz help me.
foreach (GridViewRowgridRowinthis.GridView1.Rows) { CheckBoxchbxRmove = (CheckBox)gridRow.FindControl("chkSelect"); if (chbxRmove.Checked) { //Row Index } }
I guess you are binding the Gridview data on
Page_Load
and you are not checking thePostback
properties, which reset the Grid Check box field. Try thisif(!Page.IsPostBack)
{
//BindGridViewData.
}Hope this will help you. :-D
Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you. View My Latest Article
-
I guess you are binding the Gridview data on
Page_Load
and you are not checking thePostback
properties, which reset the Grid Check box field. Try thisif(!Page.IsPostBack)
{
//BindGridViewData.
}Hope this will help you. :-D
Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you. View My Latest Article
-
And what is difference between my answer and Abhijit's answer?
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com
-
Probably checkbox is losing state on load event of Page,check it carefully. By the way,if you had problems with internet connection then delete one post of your same question.
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com
-
Hello, Ive got a problem with Gridview! I want access to column's data that is checked. and I dont know why this code doesnt work. The value of "chbxRmove.Checked" always is False even when the column is checked !!! :(( plz help me.
foreach (GridViewRowgridRowinthis.GridView1.Rows) { CheckBoxchbxRmove = (CheckBox)gridRow.FindControl("chkSelect"); if (chbxRmove.Checked) { //Row Index } }
-
also I've anather question. :-D How do I get selected row's data (Like ID)?
modified on Monday, July 27, 2009 4:46 PM
comp_j wrote:
How do am I get selected row's data (Like ID)?
There is a class GridViewRow, on SelectedIndexChnaged event of Grid, Read the current Selected Row in GridViewRow, then you can read each and every column from it. Even you can read directly the data.
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
int ID= Int32.Parse(GridView1.Rows[GridView1.SelectedIndex].Cells[0].Text);
}Note : I assume, Cell[0] of Grid contain your ID Hope this will help you :-D
Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you. View My Latest Article
-
Hello, Ive got a problem with Gridview! I want access to column's data that is checked. and I dont know why this code doesnt work. The value of "chbxRmove.Checked" always is False even when the column is checked !!! :(( plz help me.
foreach (GridViewRowgridRowinthis.GridView1.Rows) { CheckBoxchbxRmove = (CheckBox)gridRow.FindControl("chkSelect"); if (chbxRmove.Checked) { //Row Index } }