ASP.NET - problem while reading the repeater.control
Asked By aman on 05-Jan-12 06:29 AM
on the button click event i write the below code for inserting the record into my database.but compiler return 0 value for Repeater1.Controls.Count.but i have five control of checkbox inside the repeater control in my page.
for (int i = 0; i <= Repeater1.Controls.Count - 1; i++)
{
CheckBox obj = (CheckBox)Repeater1.Controls[i].FindControl("checkbox");
if (obj != null)
{
SqlConnection objConnection = new SqlConnection("Data Source=localhost;Initial Catalog=PageIssue;Integrated Security=True");
objConnection.Open();
SqlCommand objCommand = new SqlCommand();
objCommand.CommandText = "insert into tblCustomer values('" + txtCustomerName.Text + "','" + TextBox2.Text + "','" + obj.Text + "')";
objCommand.Connection = objConnection;
objCommand.ExecuteNonQuery();
objConnection.Close();
}
}
}
i have created checkbox dynamically on behind code.
SqlConnection objConnection = new SqlConnection("Data Source=localhost;Initial Catalog=PageIssue;Integrated Security=True");
objConnection.Open();
SqlCommand objCommand = new SqlCommand();
objCommand.CommandText = "select tblCategory.DataList from tblCategory where tblCategory.CatogeryID=2";
objCommand.Connection = objConnection;
objCommand.ExecuteNonQuery();
SqlDataAdapter objAdapter = new SqlDataAdapter(objCommand);
DataSet objDataSet = new DataSet();
objAdapter.Fill(objDataSet);
foreach (DataRow objDataRow in objDataSet.Tables[0].Rows)
{
for (int i = 1; i < 2; i++)
{
obj = new CheckBox();
Repeater1.Controls.Add(obj);
obj.Text = objDataRow[0].ToString();
}
}
Label1.Text=Repeater1.Controls.Count.ToString();
objConnection.Close();
}
how can i insert the the record in my database?
label1 gives it appropriate value i.e 5
thanks
regards