Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i ve small doubt gridview having template field in that i kept check box
gridview having 4 rows and 2 columns one is checkbox column and another one is firstname if i select fist row of checkbox i want to dispaly that first name in listbox agin i want to click another row means 2 or 3, if i select that i want to add in listbox but its adding firstone 2 times and third one adding


checkbox firstname(gridview 2 fields)

check xxxx (row1)

uncheck yyyy (row2)

check zzzz (row3)

uncheck aaaa (row4)

i want to add check field in listbox

but it's adding like this in list box

xxx
xxx
zzz like but i want add only xxxx,zzzz
Posted
Comments
m@dhu 20-Jan-11 0:24am    
Can you show us the code what you have done?
Rupa1 20-Jan-11 0:27am    
protected void chkcheckquery_CheckedChanged(object sender, EventArgs e)
{
CheckBox chkTest = (CheckBox)sender;
GridViewRow grdRow = (GridViewRow)chkTest.NamingContainer;

// CheckBox che = (CheckBox)grdRow.FindControl("chkcheckquery");

if (chkTest.Checked)
{
string get_value = gvqueriescheck.Rows[0].Cells[1].Text;
ListBox1.Items.Add(get_value);
}

//for (int i = 0; i < gvqueriescheck.Rows.Count; i++)
//{
// CheckBox chbTemp = gvqueriescheck.Rows[i].FindControl("chkcheckquery") as CheckBox;
// if (chbTemp.Checked)
// {
// string get_value = gvqueriescheck.Rows[i].Cells[1].Text;
// ListBox1.Items.Add(get_value);
// //Code for Deletion

// }
//}




}
Ankur\m/ 20-Jan-11 1:01am    
I would have debugged the code by putting a breakpoint on the above given method and on the line ListBox1.Items.Add(get_value);
Debugging line by line will tell you why it is happening.
Rupa1 20-Jan-11 1:42am    
sir now i got thx a lot sir
Rupa1 20-Jan-11 1:53am    
sir i ve one doubt if i check that one adding in listbox if i uncheck that item will be remove in listbox also how can i do..............?

Hi Swaroopa check the following code works for you.Add the items to Listbox out of for loop.
string get_value = "";
        for (int i = 0; i < gvqueriescheck.Rows.Count; i++)
        {
            CheckBox chbTemp = GridView1.Rows[i].FindControl("chkcheckquery") as CheckBox;
         if (chbTemp.Checked)
         {
              get_value = gvqueriescheck.Rows[i].Cells[2].Text;
         }
}
ListBox1.Items.Add(get_value); 
 
Share this answer
 
 
Share this answer
 
Comments
Hiren solanki 20-Jan-11 2:30am    
Good link downvoted . let me counter +5.

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