Wednesday, March 28, 2012

validating checkboxes - have to select only few checkboxes out of many and insert them int

Hi, I am a newbie,

I am trying to insert into Sql DB from a page. the page contains title, image and a checkbox where the user has to select only few checkboxes and when hit submit, only those selected items should be inserted. I am creating dynamically the title, image and a html input checkbox in a datagrid. here is how i am generating the checkbox. in datagrid.

<asp:TemplateColumn HeaderText ="Vote">
<ItemTemplate>
<input type ="checkbox" id ="IDs" name = "IDs" value = '<%# DataBinder.Eval(Container.DataItem, "000_filename") %>' runat ="server"/>
</ItemTemplate>
</asp:TemplateColumn>

Can anybody please help me with few tips and code, how to validate only 5 checkboxes out of all others and then insert. this is in C# 2005

Thanks in advance.

private void CheckboxValue()

{

CheckBox chkbox = newCheckBox();
TextBox txtbox= new TextBox();
foreach(DataGridItem itemin DataGrid1.Items )
{
chkbox=(CheckBox)item.FindControl("chkbox");
txtbox=(TextBox)item.FindControl("txtbox");
if(chkbox.Checked)
{
Response.Write(item.Cells[1].Text);
// write the required code for processing the checked
// records depending on the requirement.
}
}
}


Thank you so much, it works!!!

No comments:

Post a Comment