Delete Button/Function deletes the wrong data on SQL - c#

I'm using Visual Studio 2012 backed-up by SQL Server Management Studio as its database. I'm using a gridview to see my data. I used a TemplateField I can both edit and delete a data. But it seems that when I'm deleting a certain data, it always delete the first data. What might be the solution?
Here is my asp code:
<asp:Content ID="Content4" ContentPlaceHolderID="full_main" Runat="Server">
<asp:GridView ID="gvUsers" runat="server"
class="table table-bordered data-table" AutoGenerateColumns="False"
AllowPaging="True" onpageindexchanging="gvUsers_PageIndexChanging"
onselectedindexchanged="gvUsers_SelectedIndexChanged" EnableModelValidation="True">
<Columns>
<asp:BoundField DataField="UserID" HeaderText="User ID" InsertVisible="False"
ReadOnly="True" SortExpression="UserID" />
<asp:BoundField DataField="FirstName" HeaderText="First Name"
SortExpression="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="Last Name"
SortExpression="LastName" />
<asp:BoundField DataField="EmailAddress" HeaderText="Email Adress" SortExpression="EmailAddress" />
<asp:BoundField DataField="Street" HeaderText="Street" SortExpression="Street" />
<asp:BoundField DataField="Municipality" HeaderText="Municipality" SortExpression="Municipality" />
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
<asp:BoundField DataField="ZipCode" HeaderText="Zip Code" SortExpression="ZipCode" />
<asp:BoundField DataField="ContactNo" HeaderText="Contact No" SortExpression="ContactNo" />
<asp:TemplateField HeaderText="Actions">
<ItemTemplate>
<a href="http://localhost:12345/CAPSTONE/Users/Edit.aspx?ID=<%# Eval("UserID") %>"
class="btn btn-primary btn-mini">Edit</a>
Delete
<div id="deleteItem" class="modal hide">
<div class="modal-header">
<button data-dismiss="modal" class="close" type="button">×</button>
<h3>Record Deletion</h3>
</div>
<div class="modal-body">
<p>Are you sure you want to delete the record?</p>
</div>
<div class="modal-footer">
<a class="btn btn-primary"
href="http://localhost:12345/CAPSTONE/Users/Delete.aspx?ID=<%# Eval("UserID") %>">Confirm</a>
<a data-dismiss="modal" class="btn" href="#">Cancel</a>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
<center>
<h1>
No records found.</h1>
</center>
</EmptyDataTemplate>
<PagerStyle CssClass="pagination alternate" />
</asp:GridView>
Here is my code behind:
void DeleteUser(int userID)
{
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "DELETE FROM Users WHERE UserID=#UserID";
cmd.Parameters.Add("#UserID", SqlDbType.Int).Value = userID;
cmd.ExecuteNonQuery();
con.Close();
Helper.AddLog(Session["userid"].ToString(), "Delete", "Deleted a User");
Response.Redirect("Default.aspx");
}

Related

GridView - Client Side "WHERE" clause in the SqlDataSource?

I have a GridView with a TemplateField containing a button. This button opens up a modal window which contains another GridView as seen below:
Template Field in Gridview1:
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btnOpen" runat="server" Text="Show Gridview" OnClick="btnOpen_Click" data-toggle="modal" data-target="#myModal"/>
</ItemTemplate>
Modal Window:
<div class="modal" id="idModal">
<div class="container">
<div class="modal-header">
<h1>Transaction Details<a class="close-modal" href="#">×</a></h1>
</div>
<div class="modal-body">
<asp:GridView ID="gvDetail" runat="server" AutoGenerateColumns="false" DataSourceID="SqlgvDetail"
OnRowDataBound="gvDetail_RowDataBound" CssClass="table table-hover table-bordered" EmptyDataText="No data to display.">
<Columns>
<asp:BoundField DataField="metalid" HeaderText="Metal ID"/>
<asp:BoundField DataField="enddate" HeaderText="End Date" DataFormatString="{0:dd-MM-yyyy}" />
<asp:BoundField DataField="startdate" HeaderText="Start Date" DataFormatString="{0:dd-MM-yyyy}" />
<asp:BoundField DataField="clientref" HeaderText="Client Ref" />
<asp:BoundField DataField="quantity" HeaderText="Quantity" DataFormatString="{0:N2}" />
</Columns>
</asp:GridView>
</div>
<div class="modal-footer">
<asp:Button ID="btn_close" runat="server" Text="OK" CssClass="close-modal btn-sm btn-primary"/>
</div>
</div>
</div>
<div class="modal-backdrop"></div>
GridView2 SqlDataSource:
<asp:SqlDataSource ID="SqlgvDetail" runat="server" ConnectionString="<%$ ConnectionStrings:InventoryConnectionString %>"
SelectCommand="SELECT td.metalid , td.enddate , td.startdate , td.clientref , td.quantity FROM trxdetail td">
</asp:SqlDataSource>
Now this code works fine and opens up the modal window with the SelectCommand as expected. However, I need to add a where clause based on a row value from GridView1. E.g. ...WHERE td.clientref = GridView1.SelectedRow.Cells[0].Text
Help please!
Edit: Modal Window:
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
<asp:GridView ID="gvDetail" runat="server" AutoGenerateColumns="false" DataSourceID="SqlgvDetail"
OnRowDataBound="gvDetail_RowDataBound" CssClass="table table-hover table-bordered" EmptyDataText="No data to display.">
<Columns>
<asp:BoundField DataField="metalid" HeaderText="Metal ID"/>
<asp:BoundField DataField="enddate" HeaderText="End Date" DataFormatString="{0:dd-MM-yyyy}" />
<asp:BoundField DataField="startdate" HeaderText="Start Date" DataFormatString="{0:dd-MM-yyyy}" />
<asp:BoundField DataField="clientref" HeaderText="Client Ref" />
<asp:BoundField DataField="quantity" HeaderText="Quantity" DataFormatString="{0:N2}" />
</Columns>
</asp:GridView>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
Modal JS:
$(document).ready(function () {
$("#btnOpen").click(function () {
$("#myModal").modal();
});
});
You can actually set an <asp:ControlParameter> to the SelectedValue of a GridView. I think this is what you are looking for. As the documentation says:
As a further shortcut, you can directly determine the data key value of the first key field of the selected row by using the SelectedValue property.
So what you can do is set the DataKeyNames value on GridView1 to whatever value it is that you want to use in the WHERE clause.
<asp:GridView ID="GridView1" runat="server" DataKeyNames="clientref"
...
</asp:GridView>
Then set that as the control parameter in your SqlDataSource.
<asp:SqlDataSource ID="SqlgvDetail" runat="server"
ConnectionString="<%$ ConnectionStrings:InventoryConnectionString %>"
SelectCommand="SELECT td.metalid, td.enddate, td.startdate, td.clientref , td.quantity
FROM trxdetail td
WHERE clientref=#clientref">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1"
PropertyName="SelectedValue"
Name="clientref"
Type="Whatever type clientref is" />
</SelectParameters>
</asp:SqlDataSource>
Just remember you need to make sure the row in GridView1 is actually marked as the SelectedRow. You can do this in your button click event.
protected void btnOpen_Click(object sender, EventArgs e)
{
// Find the index to select
Button btnOpen = (Button)sender;
GridViewRow row = (GridViewRow)btnOpen.NamingContainer;
int selectedIndex = row.DataItemIndex;
// Set the selected index of the GridView
GridView1.SelectedIndex = selectedIndex;
// Bind the detail GridView now that the row is selected so
// that its SqlDataSource can get a SelectedValue for the
// parent GridView
gvDetail.DataBind();
}

Open a GridView using row parameters from another GridView

I am opening a modal window from the below button (btnOpen). This bhutton is located inside a GridView. It needs to open another Gridview in the modal window but my code is not working:
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btnOpen" runat="server" Text="Show Gridview" CommandName="cmdDetail" CommandArgument="<%# ((GridViewRow) Container).DataItemIndex %>"/>
</ItemTemplate>
</asp:TemplateField>
My Modal Window:
<div class="modal" id="idModal">
<div class="container">
<div class="modal-header">
<h1>Transaction Details<a class="close-modal" href="#">×</a></h1>
</div>
<div class="modal-body">
<asp:GridView ID="gvDetail" runat="server" AutoGenerateColumns="false" DataSourceID="SqlgvDetail"
OnRowDataBound="gvDetail_RowDataBound" CssClass="table table-hover table-bordered" EmptyDataText="No data to display." >
<Columns>
<asp:BoundField DataField="metalid" HeaderText="Metal ID"/>
<asp:BoundField DataField="enddate" HeaderText="End Date" DataFormatString="{0:dd-MM-yyyy}" />
<asp:BoundField DataField="startdate" HeaderText="Start Date" DataFormatString="{0:dd-MM-yyyy}" />
<asp:BoundField DataField="clientref" HeaderText="Client Ref" />
<asp:BoundField DataField="quantity" HeaderText="Quantity" DataFormatString="{0:N2}" />
</Columns>
</asp:GridView>
</div>
<div class="modal-footer">
<asp:Button ID="btn_close" runat="server" Text="OK" CssClass="close-modal btn-sm btn-primary"/>
</div>
</div>
</div>
<div class="modal-backdrop"></div>
Sql DataSource:
<asp:SqlDataSource ID="SqlgvDetail" runat="server" ConnectionString="<%$ ConnectionStrings:InventoryConnectionString %>">
</asp:SqlDataSource>
Code Behind:
protected void gvSummary_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "cmdDetail")
{
// Retrieve the row index stored in the CommandArgument property.
int index = Convert.ToInt32(e.CommandArgument);
// Retrieve the row that contains the button from the Rows collection.
GridViewRow row = gvSummary.Rows[index];
Button btnOpen = row.FindControl("btnOpen") as Button;
btnOpen.CssClass = "openModal";
string clientRef = row.Cells[0].Text;
SqlgvDetail.SelectCommand = " SELECT td.metalid , td.enddate , td.startdate , td.clientref , td.quantity FROM trxdetail td " +
" WHERE td.clientref = '" + clientRef + "'";
gvDetail.DataBind();
}
}
When I click a button it gets the SQL command correct but doesn't load the modal. If I then click the button again, It brings up the Modal with the SQL command loaded at the first click.
I've been stuck on this for days so any help is appreciated.

Firing a GridView RowCommand event from a Button inside a Template Field - C#

So I have a GridView (gvSummary) which contains a template field with a button inside (btnOpen). This button's purpose is to open a second GridView (gvDetail) in a modal window based on row information from gvSummary.
The problem I am having is that I can't seem to execute the code in gvSummary_RowCommand by clicking the button btnOpen. I can execute the code from the <asp:ButtonField> but this doesn't open the second GridView.
Here is my code:
<asp:GridView ID="gvSummary" runat="server" DataSourceID="SqlgvSummary" AutoGenerateColumns="false"
OnRowDataBound="gvSummary_RowDataBound" OnRowCommand="gvSummary_RowCommand" CssClass="table table-hover table-bordered" EmptyDataText="No data to display." >
<Columns>
<asp:BoundField DataField="ClientRef" HeaderText="Reference No."/>
<asp:BoundField DataField="InsertedWhen" HeaderText="Transaction Date" DataFormatString="{0:dd-MM-yyyy}" />
<asp:BoundField DataField="Commodity" HeaderText="Commodity" />
<asp:BoundField DataField="StartDate" HeaderText="Settlement Date" DataFormatString="{0:dd-MM-yyyy}" />
<asp:BoundField DataField="EndDate" HeaderText="Delivery Date" DataFormatString="{0:dd-MM-yyyy}" />
<asp:BoundField DataField="Value" HeaderText="Transaction Value" DataFormatString="{0:N2}" />
<asp:BoundField DataField="Fee" HeaderText="Fee" DataFormatString="{0:N2}" />
<asp:BoundField DataField="InsertedBy" HeaderText="Purchased By" />
<asp:ButtonField ButtonType="Button" CommandName="cmdDetail1" HeaderText="View Details" Text="View" ControlStyle-CssClass="openModal"/>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<div>
<asp:Button ID="btnOpen" runat="server" Text="Show Gridview" CssClass="openModal" CommandName="cmdDetail2"/>
<div class="modal" id="idModal">
<div class="container">
<div class="modal-header">
<h1>Transaction Details<a class="close-modal" href="#">×</a></h1>
</div>
<div class="modal-body">
<asp:GridView ID="gvDetail" runat="server" DataSourceID="SqlgvDetail" AutoGenerateColumns="false"
OnRowDataBound="gvDetail_RowDataBound" CssClass="table table-hover table-bordered" EmptyDataText="No data to display." >
<Columns>
<asp:BoundField DataField="metalid" HeaderText="Metal ID"/>
<asp:BoundField DataField="enddate" HeaderText="End Date" DataFormatString="{0:dd-MM-yyyy}" />
<asp:BoundField DataField="startdate" HeaderText="Start Date" DataFormatString="{0:dd-MM-yyyy}" />
<asp:BoundField DataField="clientref" HeaderText="Client Ref" />
<asp:BoundField DataField="quantity" HeaderText="Quantity" DataFormatString="{0:N2}" />
</Columns>
</asp:GridView>
</div>
<div class="modal-footer">
<asp:Button ID="btn_close" runat="server" Text="OK" CssClass="close-modal btn-sm btn-primary"/>
</div>
</div>
</div>
<div class="modal-backdrop"></div>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Code Behind:
protected void gvSummary_RowCommand(object sender, GridViewCommandEventArgs e)
{
int index = Convert.ToInt32(e.CommandArgument);
string name = e.CommandName.ToString();
string clientRef = gvSummary.Rows[index].Cells[0].Text;
Response.Write("<br> index = " + index);
Response.Write("<br> name = " + name);
Response.Write("<br> clientRef = " + clientRef);
SqlgvDetail.SelectCommand = " SELECT td.metalid , td.enddate , td.startdate , td.clientref , td.quantity " +
" FROM trxdetail td " +
" WHERE td.clientref = " + "'" + clientRef + "'";
}
When I click the <asp:ButtonField>, the SQL is correct and the Response.Write() sets the correct variables in gvSummary_RowCommand. However, the modal window doesn't open.
When I click btnOpen, the modal window opens but does not set the variables in gvSummary_RowCommand.
I can't seem to be able to egt this working so any help is appreciated.
Thanks.

Display total no of records of gridview in the Footer of Gridview

I have to display total no of records present in the gridview, for information purpose.
I want to show that in Gridview footer as
Total Records is "" records.
Here is the my gridview aspx code
<asp:GridView ID="grdTeacherProfile"
runat="server"
Width="100%"
border="1" Style="border: 1px solid #E5E5E5;"
CellPadding="3" FooterStyle-BackColor="#e3e3e3"
AutoGenerateColumns="false"
AllowPaging="true"
DataKeyNames="Id"
CssClass="hoverTable"
PageSize="10"
ShowFooter="false"
OnPreRender="PreRenderGrid"
HeaderStyle-CssClass="k-grid td"
OnDataBound="grdTeacherProfile_DataBound"
OnPageIndexChanging="grdTeacherProfile_PageIndexChanging"
OnRowDeleting="grdTeacherProfile_RowDeleting"
OnRowCommand="grdTeacherProfile_RowCommand"
EnableSortingAndPagingCallbacks="false"
EmptyDataText="No records found">
<AlternatingRowStyle CssClass="k-alt" />
<Columns>
<asp:TemplateField HeaderText="Select" ItemStyle-Width="5">
<ItemTemplate>
<asp:CheckBox ID="chkDelete" runat="server" onClick="Check_Click(this)" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="first_name" HeaderText="First Name" ItemStyle-Width="25" />
<asp:BoundField DataField="last_name" HeaderText="Last Name" ItemStyle-Width="25" />
<asp:BoundField DataField="emailid" HeaderText="Email Id" ItemStyle-Width="25" />
<asp:BoundField DataField="dob" HeaderText="Date of Birth" ItemStyle-Width="20" ApplyFormatInEditMode="true" DataFormatString="{0:d}" />
<asp:BoundField DataField="gender" HeaderText="Gender" ItemStyle-Width="20" />
<asp:BoundField DataField="designation" HeaderText="Designation" ItemStyle-Width="20" />
<asp:BoundField DataField="joining_date" HeaderText="Joining Date" ItemStyle-Width="20" ApplyFormatInEditMode="true" DataFormatString="{0:d}" />
<asp:BoundField DataField="leaving_date" HeaderText="Leaving Date" ItemStyle-Width="20" ApplyFormatInEditMode="true" DataFormatString="{0:d}" />
<asp:BoundField DataField="active" HeaderText="Active" ItemStyle-Width="25" />
<asp:TemplateField HeaderText="Action" HeaderStyle-Width="5%">
<ItemTemplate>
<asp:ImageButton ID="btnEdit" AlternateText="Edit" ImageUrl="~/images/edit.png" ToolTip="Edit" runat="server" Width="15" Height="15" CommandName="eEdit" CommandArgument='<%# Eval("Id") %>' CausesValidation="false" />
<asp:ImageButton ID="btnDelete" AlternateText="Delete" ImageUrl="~/images/delete.png" ToolTip="Delete" runat="server" Width="15" Height="15" CommandName="Delete" CommandArgument='<%# Eval("Id") %>' CausesValidation="false" OnClientClick="return confirm('Are you sure you want to delete this record?')" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle ForeColor="#e3e3e3"
BackColor="#e3e3e3" CssClass="grid-pagi" />
<PagerTemplate>
<table runat="server" id="testTable1" style="width: 100%" class="hoverTable_tbl">
<tr>
<td class="col-md-4 pull-left">
<asp:Label ID="MessageLabel"
Text="Select a page:"
runat="server" />
<asp:LinkButton ID="FirstLB" runat="server" CommandName="Page" CommandArgument="First" ToolTip="First" CssClass="btn-pager btn-default"><<</asp:LinkButton>
<asp:LinkButton ID="PrevLB" runat="server" CommandName="Page" CommandArgument="Prev" ToolTip="Previous" CssClass="btn-pager btn-default"><</asp:LinkButton>
<asp:DropDownList runat="server" ID="PageDropDownList" AutoPostBack="true" EnableViewState="true" OnSelectedIndexChanged="PageDropDownList_SelectedIndexChanged" CssClass="selectpicker form-control-drp"></asp:DropDownList>
<asp:LinkButton ID="NextLB" runat="server" CommandName="Page" CommandArgument="Next" ToolTip="Next" CssClass="btn-pager btn-default">></asp:LinkButton>
<asp:LinkButton ID="LastLB" runat="server" CommandName="Page" CommandArgument="Last" ToolTip="Last" CssClass="btn-pager btn-default">>></asp:LinkButton>
</td>
<td>
<asp:Label ID="lblRecords" runat="server" Text="sss"></asp:Label>
</td>
<td class="col-md-3">
<div>
<div class="pull-left">
<asp:Label ID="PageSizeLabel" CssClass="page-size" runat="server" Text="Select Page Size: "></asp:Label>
<asp:DropDownList ID="ddlPageSize" runat="server" OnSelectedIndexChanged="ddlPageSize_SelectedIndexChanged" AutoPostBack="true" CssClass="selectpicker form-control-drp">
<%-- <asp:ListItem Value="0" Text="0" />--%>
<asp:ListItem Value="1" Text="1" />
<asp:ListItem Value="2" Text="2" />
<asp:ListItem Value="3" Text="3" />
</asp:DropDownList>
</div>
<div>
<asp:Label ID="CurrentPageLabel" CssClass="view" runat="server" />
</div>
</div>
</td>
</tr>
</table>
</PagerTemplate>
<RowStyle />
</asp:GridView>
CS Codebehind:-
public void BindGrid()
{
string conString = ConfigurationManager.ConnectionStrings["DefaultCSRConnection"].ConnectionString;
SqlCommand cmd = new SqlCommand("Select Id, first_name, last_name,emailid, dob, gender, designation, joining_date, leaving_date, active from tbl_teachers_profile Order by Id desc");
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
grdTeacherProfile.DataSource = dt;
grdTeacherProfile.DataBind();
DisablePageDirections();
grdTeacherProfile.BottomPagerRow.Visible = true;
}
}
}
}
Please help
Writing an all new answer since the first one was way too verbose.
Set the ShowFooter="true" on your GridView. Next edit the first TemplateField like this:
<asp:TemplateField HeaderText="Select" ItemStyle-Width="5">
<ItemTemplate>
<asp:CheckBox ID="chkDelete" runat="server" onClick="Check_Click(this)" />
</ItemTemplate>
<FooterTemplate>
Number of records: <%# grdTeacherProfile.Rows.Count %>
</FooterTemplate>
</asp:TemplateField>
And that's all you should need. At least works while I tested.
There should also be some way to span the text to several columns, but didn't have time to test for that..
int RowCount = grdTeacherProfile.Rows.Count;
lblDisplayCount.Text = RowCount.ToString();
Try this code.

how to print multiple barcodes on single click

I want to print different barcodes from gridview on a single click. I tried but it doesn't work... and it should generate barcodes according to the quantity... this is code...
this is my grid with print button..
<div class="col-xs-1">
<asp:Button ID="btnprintbc" runat="server" Text="Print Barcode" class="width-65 pull-right btn btn-sm btn-success" OnClick="btnprintbc_Click" />
</div>
<div class="table-responsive">
<asp:GridView ID="gvrec" class="table table-striped table-bordered table-hover" AllowPaging="False" AllowSorting="True" AutoGenerateColumns="False" ShowHeader="true" DataKeyNames="nv_recid" EnableViewState="true" runat="server">
<Columns>
<asp:BoundField DataField="nv_recid" HeaderText="S.NO" SortExpression="nv_recid" />
<asp:TemplateField >
<HeaderTemplate>
<asp:TextBox ID="txtcc" placeholder="Search..." runat="server" class="nav-search-input" Width="210"></asp:TextBox>
<asp:Button ID="btnSearch" runat="server" Text="Search" CommandName="Search" />
</HeaderTemplate>
</asp:TemplateField>
<asp:BoundField DataField="nGRN" SortExpression="nGRN" HeaderText="GRN" />
<asp:BoundField DataField="strVendorName" SortExpression="nGRN" HeaderText="Vendor Name" />
<asp:TemplateField HeaderText="Bill NO">
<ItemTemplate>
<asp:Label ID="lblbn" runat="server" Text='<%# Eval("strBillNO") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="bnSKU" SortExpression="bnSKU" HeaderText="Barcode" />
<asp:BoundField DataField="strDescription" SortExpression="strDescription" HeaderText="Description" />
<asp:BoundField DataField="nQTY" SortExpression="nQTY" HeaderText="Quantity" />
<asp:BoundField DataField="nCost" SortExpression="nCost" HeaderText="Cost Price" />
<asp:BoundField DataField="nTotalCost" SortExpression="nTotalCost" HeaderText="Total Cost" />
<asp:BoundField DataField="nRetail" SortExpression="nRetail" HeaderText="Retail Price" />
<asp:BoundField DataField="nTotalRetail" SortExpression="nTotalRetail" HeaderText="Total Retail" />
<asp:BoundField DataField="dtAddDate" SortExpression="dtAddDate" HeaderText="Date" />
</Columns>
</asp:GridView>
barcode printing code is here....
lblsize.Text = Session["price"].ToString();
getCodetxt.Text = Session["SKU"].ToString();
int W = Convert.ToInt32("130");
int H = Convert.ToInt32("40");
b.IncludeLabel = true;
BarcodeLib.TYPE type = BarcodeLib.TYPE.CODE128C;
Bitmap btmap = (Bitmap)b.Encode(type, getCodetxt.Text.Trim(), System.Drawing.Color.Black, System.Drawing.Color.White, W, H);
btmap.Save(AppDomain.CurrentDomain.BaseDirectory + "/Attachments/BarCodes/" + getCodetxt.Text + ".jpeg", ImageFormat.Jpeg);
img.ImageUrl = "~/Attachments/BarCodes/" + getCodetxt.Text + ".jpeg";
Session["URL"] = "~/Attachments/BarCodes/" + getCodetxt.Text + ".jpeg";
Session["imageUrl"] = Session["URL"].ToString();
Session["Number"] = Session["val"];
How could I generate different barcodes according to their quantity given in grid?

Categories

Resources