Hi AliYilmaz,
I have created a sample which full fill your requirement you need to modify the code according to your need and keep in mind that there is no need of adding check change event to checkbox if you assign the check change event to it then also there is no use of it because you wont get any data as the data gets binded dynamically which is accessible at client not at server side and because of check event change the page gets postback and dynamically added data gets lost so the gridview wont get displayed.
Refer below sample
HTML
<div>
Category:-
<asp:TextBox ID="txtkategori" runat="server" />
<br />
<br />
<asp:ScriptManager runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="example" CssClass="table table-striped table-bordered table-hover"
Style="display: none" AutoGenerateColumns="false" runat="server" OnRowDataBound="example_RowDataBound"
ClientIDMode="Static">
<Columns>
<asp:TemplateField ItemStyle-CssClass="IgnoreCheckBoxColumn" HeaderText="Ürün Seç"
ItemStyle-Width="5%">
<ItemTemplate>
<asp:CheckBox ID="chcsec" CssClass="form-control" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Ürün Ad" ItemStyle-Width="22%">
<ItemTemplate>
<asp:Label ID="lblUrun" runat="server" Text='<%# Eval("UrunAd") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Stok" ItemStyle-Width="5%">
<ItemTemplate>
<asp:Label ID="lblStok" Style="padding: 3px 5px;" runat="server" Text='<%# Eval("Stok") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Seri No" ItemStyle-Width="15%">
<ItemTemplate>
<asp:Label ID="lblSeriNo" Style="padding: 3px 5px;" runat="server" Text='<%# Eval("SeriNo") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Tedarikçi" ItemStyle-Width="15%">
<ItemTemplate>
<asp:Label ID="lblTedarik" Style="padding: 3px 5px;" runat="server" Text='<%# Eval("TedarikcilID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Adet" ItemStyle-Width="50">
<ItemTemplate>
<asp:TextBox ID="lblAdet" Style="padding: 3px 5px; width: 100%" CssClass="form-control"
runat="server"></asp:TextBox>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtAdet" runat="server" Style="padding: 3px 5px; width: 100%" CssClass="form-control"></asp:TextBox>
</EditItemTemplate>
</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:TextBox ID="lblElemanAdet" Style="padding: 3px 5px; width: 100%" CssClass="form-control"
runat="server"></asp:TextBox>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtElemanAdet" runat="server" Style="padding: 3px 5px; width: 100%"
CssClass="form-control"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Tedarikçi Fiyat" ItemStyle-Width="50">
<ItemTemplate>
<asp:TextBox ID="lblTedarikciFiyat" Style="padding: 3px 5px; width: 100%" CssClass="form-control"
runat="server"></asp:TextBox>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtTedarikciFiyat" runat="server" Style="padding: 3px 5px; width: 100%"
CssClass="form-control"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
<br />
<asp:GridView ID="gvCopied" Style="display: none" CssClass="table table-striped table-bordered table-hover"
runat="server">
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.9.2/jquery-ui.min.js" type="text/javascript"></script>
<link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.9.2/themes/blitzer/jquery-ui.css"
rel="Stylesheet" type="text/css" />
<script type="text/javascript" src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<script type="text/javascript">
$(function () {
$('[id*=txtkategori]').autocomplete({
source: function (request, response) {
$.ajax({
url: "Default.aspx/Kategori",
data: "{ 'q': '" + request.term + "'}",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (data) {
if (data.d.length > 0) {
response($.map(data.d, function (item) {
return {
label: item,
val: item
};
}))
} else {
response([{ label: 'No results found.', val: -1}]);
}
}
});
},
minLength: 1
});
$('[id*=txtkategori]').keyup(function () {
var obj = {};
obj.value = $(this).val();
$.ajax({
url: "Default.aspx/BindProductTable",
data: JSON.stringify(obj),
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (data) {
if (data.d != "Please Enter Valid Category" && data.d != "No Data Found!!") {
var xmlDoc = $.parseXML(data.d);
var xml = $(xmlDoc);
var Products = xml.find("Products");
var row = $("[id*=example] tr:last-child").clone(true);
$("[id*=example] tr").not($("[id*=example] tr:first-child")).remove();
$.each(Products, function () {
var product = $(this);
$("td", row).eq(1).html($(this).find("UrunAd").text());
$("td", row).eq(2).html($(this).find("Stok").text());
$("td", row).eq(3).html($(this).find("SeriNo").text());
$("td", row).eq(4).html($(this).find("TedarikcilID").text());
$("[id*=example]").append(row);
row = $("[id*=example] tr:last-child").clone(true);
});
$("[id*=example]").attr('style', 'display:block');
}
else {
$("[id*=example]").attr('style', 'display:none');
alert(data.d);
}
},
error: function (data) { alert(data.d); }
});
});
$('[id*=chcsec]').click(function () {
$("[id*=gvCopied] tr").eq(1).attr('style', '');
if ($(this).is(':checked')) {
var row = $("[id*=gvCopied] tr").eq(1).clone(true);
$("[id*=gvCopied] tr").eq(1).attr('style', 'display:none');
var rowDetails = $(this).closest('tr');
$("td", row).eq(0).html($(rowDetails).find('td').eq(1).html());
$("td", row).eq(1).html($(rowDetails).find('td').eq(2).html());
$("td", row).eq(2).html($(rowDetails).find('td').eq(3).html());
$("td", row).eq(3).html($(rowDetails).find('td').eq(4).html());
$("td", row).eq(4).html($(rowDetails).find('td').eq(5).find('[id*=lblAdet ]').val());
$("td", row).eq(5).html($(rowDetails).find('td').eq(6).find('[id*=drpEleman] option:selected').val());
$("td", row).eq(6).html($(rowDetails).find('td').eq(7).find('[id*=lblElemanAdet ]').val());
$("td", row).eq(7).html($(rowDetails).find('td').eq(8).find('[id*=lblTedarikciFiyat ]').val());
$('[id*=gvCopied]').append(row);
row = $("[id*=gvCopied] tr:last-child").clone(true);
$('[id*=gvCopied]').attr('style', 'display:block');
}
else {
var lblUrun = $(this).closest('tr').find('td').eq(1).html();
$('[id*=gvCopied] tr').each(function () {
if ($(this).find('td').eq(0).html() == lblUrun) {
var rowIndex = $(this)[0].rowIndex;
$('[id*=gvCopied] tr').eq(rowIndex).remove();
$("[id*=gvCopied] tr").eq(1).attr('style', 'display:none');
}
if ($('[id*=gvCopied] tr').length == 2) {
$('[id*=gvCopied]').attr('style', 'display:none');
}
});
}
});
});
</script>
</div>
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[] {
new DataColumn("UrunAd")
,new DataColumn("Stok")
,new DataColumn("SeriNo")
,new DataColumn("TedarikcilID")
,new DataColumn("Adet")
,new DataColumn("Eleman Seç")
,new DataColumn("Eleman Adet")
,new DataColumn("Tedarikçi Fiyat")
});
dt.Rows.Add();
example.DataSource = dt;
example.DataBind();
gvCopied.DataSource = dt;
gvCopied.DataBind();
}
}
protected void example_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList drpEleman = e.Row.FindControl("drpEleman") as DropDownList;
drpEleman.DataSource = BindDropDownlist();
drpEleman.DataTextField = "Country";
drpEleman.DataBind();
drpEleman.Items.Insert(0, new ListItem("Please Select"));
}
}
[WebMethod]
public static List<string> Kategori(string q)
{
List<string> kategori = new List<string>();
using (Entities medya = new Entities())
{
kategori = (from v in medya.Kategoris where v.KategoriAd.StartsWith(q) select v.KategoriAd).ToList();
}
return kategori;
}
[WebMethod]
public static string BindProductTable(string value)
{
if (!string.IsNullOrEmpty(value))
{
using (Entities medya = new Entities())
{
var uruns = (from b in medya.Urunlers
join c in medya.Kategoris on b.KatID equals c.ID into product
from prod in product
where prod.KategoriAd.StartsWith(value)
select new { b.ID, b.UrunAd, b.Stok, b.SeriNo, b.TedarikcilID }).Where(x => x.Stok > 0).ToList();
DataTable dt = new DataTable("Products");
dt.Columns.AddRange(new DataColumn[4] { new DataColumn("UrunAd"), new DataColumn("Stok"), new DataColumn("SeriNo"), new DataColumn("TedarikcilID") });
for (int i = 0; i < uruns.Count; i++)
{
dt.Rows.Add(uruns[i].UrunAd, uruns[i].Stok, uruns[i].SeriNo, uruns[i].TedarikcilID);
}
if (dt.Rows.Count > 0)
{
DataSet ds = new DataSet();
ds.Tables.Add(dt);
return ds.GetXml();
}
else
{
return "No Data Found!!";
}
}
}
else
{
return "Please Enter Valid Category";
}
}
public DataTable BindDropDownlist()
{
DataTable dt = new DataTable();
dt.Columns.Add("Country");
dt.Rows.Add("United States");
dt.Rows.Add("India");
dt.Rows.Add("France");
dt.Rows.Add("Russia");
return dt;
}
Screenshot
