Hi
I want to send checkbox checked value to next page and display in a gridview. I only get a single value even if the multiple checkboxes are checked.
<asp:GridView ID="GridView1" CssClass="table table-responsive table-striped" runat="server" CellPadding="3" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" >
<Columns>
<asp:TemplateField>
<EditItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</EditItemTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<a href="#" onclick='openPopup("<%# Eval("fig_Item_No")%>","<%# Eval("Part_number")%>","<%#Convert.ToBase64String((byte[])Eval("Image"))%>","<%# Eval("Vendor_Code")%>")'>Details</a>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Image ID="Image1" Width="150px" Height="50px" runat="server" ImageUrl='<%#"data:Image/jpg;base64," + Convert.ToBase64String((byte[])Eval("Image")) %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="White" ForeColor="#000066" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
<PagerStyle ForeColor="#000066" HorizontalAlign="Left" BackColor="White" />
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#007DBB" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#00547E" />
</asp:GridView>
<!--/.Card-->
<br />
<asp:Button ID="btnadd" OnClick="btnadd_Click" CssClass="btn btn-success ml-3" runat="server" Text="Add To Cart" Width="400px" />
protected void btnadd_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["connString"].ConnectionString);
StringBuilder strb = new StringBuilder();
foreach(GridViewRow row in GridView1.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
bool isChecked = (row.FindControl("CheckBox1") as CheckBox).Checked;
if (isChecked)
{
// strb.Append(GridView1.Rows[i].Cells[7].Text ).AppendLine();
strb.Append(GridView1.Rows[0].Cells[9].Text).AppendLine();
}
}
}
// Session["vendor"] = strb.ToString();
Session["vendor"] = strb.ToString().Trim('\n');
Response.Redirect("order.aspx");
}
order.aspx
if (!this.IsPostBack)
{
if (Session["vendor"] != null)
{
GetGridviewData();
}
}
public void GetGridviewData()
{
string[] vendors = Session["vendor"].ToString().Split('\n');
foreach (string vendor in vendors)
{
var data = vendor.Trim();
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["connString"].ConnectionString);
SqlCommand cmd = new SqlCommand("select Id,[Part_number],Nomenclature,[Vendor_Code],quantity,[quantity_available],[unit_price] from Catalouge where [Vendor_Code]=('" + data + "')", conn);
Gridorder.DataSource = this.ExecuteQuery(cmd, "SELECT");
Gridorder.DataBind();
}
}
private DataTable ExecuteQuery(SqlCommand cmd, string action)
{
string conString = (ConfigurationManager.ConnectionStrings["connString"].ConnectionString);
using (SqlConnection con = new SqlConnection(conString))
{
cmd.Connection = con;
switch (action)
{
case "SELECT":
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
return dt;
}
}
case "UPDATE":
con.Open();
cmd.ExecuteNonQuery();
con.Close();
break;
}
return null;
}
}