Greetings
I have a gridview and a dropdownlist. I want to get the selected value from the dropdownlist and all the checked values in the gridview and insert them into the datbase through a stored proc.
Here is my code:
protected void btnAddToList_Click(object sender, EventArgs e)
{
for (int z = 0; z < this.gvViewList.Rows.Count; z++)
{
bool ifchecked = ((CheckBox)gvViewList.Rows[z].FindControl("chkSelect")).Checked;
//int id = ((CheckBox)gvViewList.Rows[z].FindControl("chkSelect")).Checked;
if (ifchecked)
{
SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["Eddition2ConnectionString"].ToString());
SqlCommand cmd = new SqlCommand();
try
{
cn.Open();
cmd.Connection = cn;
cmd.CommandText = "procinsert"
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@ListID", ddlList.SelectedValue));
cmd.Parameters.Add(new SqlParameter("@UserID.SelectedValue));
}
finally
{
if (cn != null)
{
cn.Close();
}
}
}
}
my frontend
<Columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" />
</ItemTemplate>
<HeaderTemplate>
<input id="chkAll" onclick="javascript:SelectAllCheckboxes(this);" runat="server"
type="checkbox" />
</HeaderTemplate>
</asp:TemplateField>
I have a gridview and a dropdownlist. I want to get the selected value from the dropdownlist and all the checked values in the gridview and insert them into the datbase through a stored proc.
Here is my code:
protected void btnAddToList_Click(object sender, EventArgs e)
{
for (int z = 0; z < this.gvViewList.Rows.Count; z++)
{
bool ifchecked = ((CheckBox)gvViewList.Rows[z].FindControl("chkSelect")).Checked;
//int id = ((CheckBox)gvViewList.Rows[z].FindControl("chkSelect")).Checked;
if (ifchecked)
{
SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["Eddition2ConnectionString"].ToString());
SqlCommand cmd = new SqlCommand();
try
{
cn.Open();
cmd.Connection = cn;
cmd.CommandText = "procinsert"
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@ListID", ddlList.SelectedValue));
cmd.Parameters.Add(new SqlParameter("@UserID.SelectedValue));
}
finally
{
if (cn != null)
{
cn.Close();
}
}
}
}
my frontend
<Columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" />
</ItemTemplate>
<HeaderTemplate>
<input id="chkAll" onclick="javascript:SelectAllCheckboxes(this);" runat="server"
type="checkbox" />
</HeaderTemplate>
</asp:TemplateField>
Last edited: