Hi AliYilmaz,
Please refer below code which satisfiy your requirement
HTML
<div>
<asp:DropDownList runat="server" AutoPostBack="true" OnSelectedIndexChanged="OnChange"
ID="ddlCategory">
<asp:ListItem Text="Select" />
<asp:ListItem Text="UrunAd 1" />
<asp:ListItem Text="UrunAd 2" />
<asp:ListItem Text="UrunAd 3" />
<asp:ListItem Text="UrunAd 4" />
</asp:DropDownList>
<br />
<br />
<asp:GridView ID="example" AutoGenerateColumns="false" DataKeyNames="ID" runat="server"
ClientIDMode="Static" OnRowDataBound="example_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="Ürün Seç" ItemStyle-Width="50">
<ItemTemplate>
<asp:CheckBox ID="chcsec" CssClass="form-control" runat="server" AutoPostBack="true"
OnCheckedChanged="chcsec_CheckedChanged" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Ürün Ad" ItemStyle-Width="100">
<ItemTemplate>
<asp:Label ID="lblUrun" runat="server" Text='<%# Eval("UrunAd") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Stok" ItemStyle-Width="50">
<ItemTemplate>
<asp:Label ID="lblStok" Style="padding: 3px 5px;" runat="server" Text='<%# Eval("Stok") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Fiyat" ItemStyle-Width="50">
<ItemTemplate>
<asp:Label ID="txtfiyat" Style="padding: 3px 5px;" CssClass="form-control" runat="server">500</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Adet" ItemStyle-Width="50">
<ItemTemplate>
<asp:Label ID="txtAdet" Style="padding: 3px 5px;" CssClass="form-control" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Eleman Seç" ItemStyle-Width="100">
<ItemTemplate>
<asp:DropDownList ID="drpEleman" CssClass="form-control" runat="server">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Eleman Adet" ItemStyle-Width="50">
<ItemTemplate>
<asp:Label ID="txtElemanAdet" Style="padding: 3px 5px;" CssClass="form-control" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Eleman Fiyat" ItemStyle-Width="50">
<ItemTemplate>
<asp:Label ID="txtElemanFiyat" Style="padding: 3px 5px;" CssClass="form-control"
runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ButtonType="Link" ShowEditButton="true" ShowDeleteButton="true"
ItemStyle-Width="150" />
</Columns>
</asp:GridView>
<br />
<asp:GridView runat="server" ID="gvSiparis" />
</div>
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
BindGrid("");
}
}
private void BindGrid(string category)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[] { new DataColumn("ID", typeof(int)), new DataColumn("UrunAd"), new DataColumn("Stok", typeof(int)) });
dt.Rows.Add(1, "UrunAd 1", 10);
dt.Rows.Add(2, "UrunAd 2", 15);
dt.Rows.Add(3, "UrunAd 3", 8);
dt.Rows.Add(4, "UrunAd 4", 2);
dt.Rows.Add(5, "UrunAd 3", 6);
dt.Rows.Add(6, "UrunAd 2", 9);
dt.Rows.Add(7, "UrunAd 1", 1);
dt.Rows.Add(8, "UrunAd 4", 18);
dt.Rows.Add(9, "UrunAd 4", 14);
if (string.IsNullOrEmpty(category))
{
example.DataSource = dt;
}
else
{
string expression = "UrunAd = '" + category + "'";
dt.DefaultView.RowFilter = expression;
example.DataSource = dt;
}
example.DataBind();
}
protected void chcsec_CheckedChanged(object sender, EventArgs e)
{
if ((sender as CheckBox).Checked)
{
if (ViewState["CheckedRow"] == null)
{
DataTable dt = CheckedData();
ViewState["CheckedRow"] = dt;
}
else
{
DataTable previousCheckedRows = ViewState["CheckedRow"] as DataTable;
DataTable dtCurrentCheckedRows = CheckedData();
dtCurrentCheckedRows.Merge(previousCheckedRows);
ViewState["CheckedRow"] = dtCurrentCheckedRows;
}
}
else
{
GridViewRow row = ((sender as CheckBox).NamingContainer as GridViewRow);
Label lblUrun = (row.FindControl("lblUrun") as Label);
Label lblStok = (row.FindControl("lblStok") as Label);
DataTable deleteRow = (ViewState["CheckedRow"] as DataTable).DefaultView.ToTable(true);
DataRow[] dr = deleteRow.Select("UrunAd = '" + lblUrun.Text + "' AND Stok = '" + lblStok.Text + "'");
foreach (DataRow d in dr)
{
deleteRow.Rows.Remove(d);
}
ViewState["CheckedRow"] = deleteRow;
}
gvSiparis.DataSource = (ViewState["CheckedRow"] as DataTable).DefaultView.ToTable(true);
gvSiparis.DataBind();
}
private DataTable CheckedData()
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[] { new DataColumn("UrunAd"), new DataColumn("Stok", typeof(int)), new DataColumn("Pozisyon") });
foreach (GridViewRow rw in example.Rows)
{
if (rw.RowType == DataControlRowType.DataRow)
{
CheckBox chk = (CheckBox)rw.Cells[0].FindControl("chcsec");
Label lb = (Label)rw.Cells[1].FindControl("lblUrun");
Label lb1 = (Label)rw.Cells[2].FindControl("lblStok");
DropDownList drpEleman = (DropDownList)rw.Cells[5].FindControl("drpEleman");
if (chk.Checked)
{
dt.Rows.Add(lb.Text, lb1.Text, drpEleman.SelectedItem.Value);
}
}
}
return dt;
}
protected void OnChange(object sender, EventArgs e)
{
BindGrid(ddlCategory.SelectedItem.Text.Trim());
}
protected void example_RowDataBound(object sender, GridViewRowEventArgs e)
{
//Your DataBase Table Bind to DataTable here.
DataTable dropdownBindTable = new DataTable();
dropdownBindTable.Columns.AddRange(new DataColumn[] { new DataColumn("Pozisyon"), new DataColumn("ID") });
dropdownBindTable.Rows.Add("Pozisyon1", 1);
dropdownBindTable.Rows.Add("Pozisyon2", 2);
dropdownBindTable.Rows.Add("Pozisyon3", 3);
dropdownBindTable.Rows.Add("Pozisyon4", 4);
dropdownBindTable.Rows.Add("Pozisyon5", 5);
if (e.Row.RowType == DataControlRowType.DataRow)
{
//You need to bind dropdownlist once and it will apply to all rows dropdownlist.
DropDownList drpEleman = (e.Row.FindControl("drpEleman") as DropDownList);
drpEleman.DataSource = dropdownBindTable;
drpEleman.DataTextField = "Pozisyon";
drpEleman.DataValueField = "ID";
drpEleman.DataBind();
drpEleman.Items.Insert(0, new ListItem("Please Select", ""));
}
}
ScreenShot