<asp:gridview id="example" cssclass="table table-striped table-bordered table-hover" autogeneratecolumns="false" datakeynames="ID" runat="server" clientidmode="Static" onprerender="example_PreRender" onrowediting="example_RowEditing" onrowcancelingedit="example_RowCancelingEdit" onrowdeleting="example_RowDeleting" onrowdatabound="example_RowDataBound" ondatabound="example_DataBound">
<columns>
<asp:templatefield headertext="Ürün Seç" itemstyle-width="50">
<itemtemplate>
<asp:checkbox id="chcsec" cssclass="form-control" runat="server" autopostback="true">
</asp:checkbox></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>
<edititemtemplate>
<asp:textbox id="txturunad" runat="server" text="<%# Eval("UrunAd") %>"></asp:textbox>
</edititemtemplate>
</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>
<edititemtemplate>
<asp:textbox id="txtstok" style="padding: 3px 5px;" runat="server" text="<%# Eval("Stok") %>"></asp:textbox>
</edititemtemplate>
</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>
<edititemtemplate>
<asp:textbox id="txtfiyat" style="padding: 3px 5px;" runat="server" cssclass="form-control"></asp:textbox>
</edititemtemplate>
</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>
<edititemtemplate>
<asp:textbox id="txtAdet" runat="server" style="padding: 3px 5px;" 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:label id="txtElemanAdet" style="padding: 3px 5px;" cssclass="form-control" runat="server"></asp:label>
</itemtemplate>
<edititemtemplate>
<asp:textbox id="txtElemanAdet" runat="server" style="padding: 3px 5px;" cssclass="form-control"></asp:textbox>
</edititemtemplate>
</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>
<edititemtemplate>
<asp:textbox id="txtElemanFiyat" runat="server" style="padding: 3px 5px;" cssclass="form-control"></asp:textbox>
</edititemtemplate>
</asp:templatefield>
<asp:commandfield buttontype="Link" showeditbutton="true" showdeletebutton="true" itemstyle-width="150">
</asp:commandfield></columns>
</asp:gridview>
------------------------------------------------------------------------------------
if (!Page.IsPostBack)
{
//Uruns();
//Projes();
//Siparislers();
Elemans();
Musteris();
Kategoris();
}
else
{
List<object> datakeys = ViewState["datakeys"] != null ?
(List<object>)ViewState["datakeys"] : new List<object>();
foreach (GridViewRow row in example.Rows)
if (((CheckBox)row.FindControl("chcsec")).Checked)
{
datakeys.Add(example.DataKeys[row.RowIndex].Value);
}
else
{
datakeys.Remove(example.DataKeys[row.RowIndex].Value);
}
ViewState["datakeys"] = datakeys;
}
-----------------------------------------------------------
protected void example_DataBound(object sender, EventArgs e)
{
//Session.Add("arrcon", arr);
if (example.Rows.Count > 0 && ViewState["datakeys"] != null)
{
List<object> datakeys = (List<object>)ViewState["datakeys"];
foreach (GridViewRow row in example.Rows)
((CheckBox)row.FindControl("chcsec")).Checked = datakeys.Contains(example.DataKeys[row.RowIndex].Value);
}
}
protected void btnTopla_Click(object sender, EventArgs e)
{
if (example.Rows.Count > 0 && ViewState["datakeys"] != null)
{
int sonuc = 0;
List<object> datakeys = (List<object>)ViewState["datakeys"];
int i = 0;
foreach (GridViewRow row in example.Rows)
{
((CheckBox)row.FindControl("chcsec")).Checked = datakeys.Contains(example.DataKeys[row.RowIndex].Value);
var lblFiyat = row.FindControl("txtfiyat") as Label;
int sayi1 = Convert.ToInt32(lblFiyat.Text);
i++;
sonuc = sayi1 * i;
}
txtToplamfiyat.Text = sonuc.ToString();
}
}