how to print multiple barcodes on single click - c#

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?

Related

Not able to access hyperlink column inside gridview from code behind

I want to access the HyperLinkField column of the GridView from code behind but I am unable to do so.
I have the column in my dataset but I am still not able to use it.
My HyperLinkField column is named Status.
Here is what I tried:
UltraWebGrid1.DataSource = ObjPriDsGrid;
UltraWebGrid1.DataBind();
string StrPriStatus = "";
for (int IntPriI = 0; IntPriI < UltraWebGrid1.Rows.Count; IntPriI++)
{
if (UltraWebGrid1.Rows[IntPriI].Cells[6].Text.Trim() != null)
{
StrPriStatus = UltraWebGrid1.Rows[IntPriI].Cells[6].Text.Trim();
}
else
{
}
if (StrPriStatus == "5")
{
UltraWebGrid1.Rows[IntPriI].Cells[8].Text = ""; // Not getting status column here
}
}
Here is my GridView:
<asp:GridView ID="UltraWebGrid1" ShowHeader="true" runat="server" AutoGenerateColumns="false"
DataKeyNames="mkey" OnRowDataBound="Grid_RowDataBound" Width="98%" Height="30%"
PageSize="10" AllowPaging="true" OnPageIndexChanging="Grid1_PageIndexChanging"
ShowFooter="true" CssClass="Grid">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<img alt="" style="cursor: pointer" src="../../../Images/plus.png" />
<asp:Panel ID="pnlGrid" runat="server" Style="display: none">
<asp:GridView ID="Grid2" runat="server" AutoGenerateColumns="false" Width="600px"
CssClass="ChildGrid">
<Columns>
<asp:BoundField ItemStyle-Width="80px" DataField="RefMkey" HeaderText="Mkey" />
<asp:BoundField ItemStyle-Width="150px" DataField="CurrentUser" HeaderText="Current User" />
<asp:BoundField ItemStyle-Width="180px" DataField="Department" HeaderText="Current Department" />
<asp:BoundField ItemStyle-Width="100px" DataField="remarks" HeaderText="Remarks" />
</Columns>
</asp:GridView>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField ItemStyle-Width="0px" DataField="mkey" Visible="false" HeaderText="Mkey" />
<asp:BoundField ItemStyle-Width="8%" DataField="Doc_No" HeaderText="IW/ No" />
<asp:BoundField ItemStyle-Width="10%" DataField="Doc_Date" HeaderText="IW/ Date" />
<asp:BoundField ItemStyle-Width="12%" DataField="DocType" HeaderText="Doc type" />
<asp:BoundField ItemStyle-Width="15%" DataField="Party_Name" HeaderText="Party Name" />
<asp:BoundField ItemStyle-Width="0" Visible="true" DataField="Status_Flag" HeaderText="Status" />
<asp:BoundField ItemStyle-Width="10%" DataField="LastAction_datetime" HeaderText="Last Action Date" />
<asp:BoundField ItemStyle-Width="10%" DataField="CurrStatus" HeaderText="Current Status" />
<asp:BoundField ItemStyle-Width="10%" DataField="Type_desc" HeaderText="Resp Dept" />
<asp:BoundField ItemStyle-Width="12%" DataField="UserName" HeaderText="Resp User" />
<asp:BoundField ItemStyle-Width="8%" DataField="No_Of_Days" HeaderText="No of days" />
<asp:HyperLinkField ItemStyle-Width="5%" DataNavigateUrlFields="Mkey, Status, Doc_No"
DataNavigateUrlFormatString="~/Administration/Dispatch/Inward/FrmInwardNextAction.aspx?Inward_mkey={0}&Status={0}&IWNO={0}"
HeaderText="Status" DataTextField="Status" Target="_blank" />
<asp:HyperLinkField ItemStyle-Width="5%" DataNavigateUrlFields="Mkey, Status, Doc_No"
HeaderText="View" DataTextField="View" Target="_blank" DataNavigateUrlFormatString="~/Administration/Dispatch/Inward/InwardDocDetails.aspx?Key={0}&Status={0}&IWNO={0}" />
</Columns>
</asp:GridView>
Columns like HyperLinkField and CheckBoxField behave a little differently than BoundField. They don't just simply contain text like BoundField. You have to get the control within the cell. You can get the child controls of the cell using the Controls collection. We know that specifically for a HyperLinkField, the HyperLink will be the first control in the collection.
HyperLink hyp = (HyperLink)UltraWebGrid1.Rows[IntPriI].Cells[12].Controls[0];
Can you try it like this
if (StrPriStatus == "5")
{
HyperLink HyperLinkObj = (HyperLink)UltraWebGrid1.Rows[IntPriI].Cells[12].Controls[0];
HyperLinkObj.Text = "";
}

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.

Two Item templates in one Template field?

Is it possible to have two item templates in one template field? This is my current code and its not working because when I run it e.Row.FindControl("gvQuoteItems") always returns null:
ASPX:
<asp:TemplateField ItemStyle-Width="50px">
<ItemTemplate>
<img alt="" style="cursor: pointer" src="images/plus.png" />
<asp:Panel ID="pnlQuoteItems" runat="server" Style="display: none">
<asp:GridView ID="gvQuoteItems" runat="server" AutoGenerateColumns="false" CssClass="GridView" OnRowDeleting="gvQuote_RowDeleting" ShowFooter="True">
<Columns>
<asp:CommandField ShowDeleteButton="True" />
<asp:BoundField DataField="QuoteItemID" HeaderText="QuoteItemID" SortExpression="QuoteItemID" Visible="false" />
<asp:BoundField DataField="Category" HeaderText="Category" SortExpression="Category" Visible="false" />
<asp:BoundField DataField="Cover" HeaderText="Cover" SortExpression="Cover" />
<asp:BoundField DataField="CoverType" HeaderText="Cover Type" SortExpression="CoverType" Visible="false" />
<asp:BoundField DataField="SumInsured" HeaderText="Sum Insured" SortExpression="SumInsured" />
<asp:BoundField DataField="Rate" HeaderText="Rate" SortExpression="Rate" />
<asp:BoundField DataField="AnnualPremium" HeaderText="Annual Premium" SortExpression="AnnualPremium" />
<asp:BoundField DataField="MonthlyPremium" HeaderText="Monthly Premium" SortExpression="MonthlyPremium" />
</Columns>
<FooterStyle BackColor="#022439" Font-Bold="True" ForeColor="White" />
<EmptyDataTemplate>
No Data To Display!
</EmptyDataTemplate>
</asp:GridView>
</asp:Panel>
</ItemTemplate>
<ItemTemplate>
<img alt="" style="cursor: pointer" src="images/plus.png" />
<asp:Panel ID="pnlMotorQuoteItems" runat="server" Style="display: none">
<asp:GridView ID="gvMotorQuoteItems" runat="server" AutoGenerateColumns="false" CssClass="GridView" OnRowDeleting="gvQuote_RowDeleting" ShowFooter="True">
<Columns>
<asp:CommandField ShowDeleteButton="True" />
<asp:BoundField DataField="QuoteItemID" HeaderText="QuoteItemID" SortExpression="QuoteItemID" Visible="false" />
<asp:BoundField DataField="Category" HeaderText="Category" SortExpression="Category" Visible="false" />
<asp:BoundField DataField="Year" HeaderText="Year" SortExpression="Year" />
<asp:BoundField DataField="MakeAndModel" HeaderText="Make And Model" SortExpression="MakeAndModel" />
<asp:BoundField DataField="NCB" HeaderText="NCB" SortExpression="NCB" />
<asp:BoundField DataField="Cover" HeaderText="Cover" SortExpression="Cover" />
<asp:BoundField DataField="CoverType" HeaderText="Cover Type" SortExpression="CoverType" Visible="false" />
<asp:BoundField DataField="SumInsured" HeaderText="Sum Insured" SortExpression="SumInsured" />
<asp:BoundField DataField="Rate" HeaderText="Rate" SortExpression="Rate" />
<asp:BoundField DataField="AnnualPremium" HeaderText="Annual Premium" SortExpression="AnnualPremium" />
<asp:BoundField DataField="MonthlyPremium" HeaderText="Monthly Premium" SortExpression="MonthlyPremium" />
</Columns>
<FooterStyle BackColor="#022439" Font-Bold="True" ForeColor="White" />
<EmptyDataTemplate>
No Data To Display!
</EmptyDataTemplate>
</asp:GridView>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
Code-behind:
if (e.Row.RowType == DataControlRowType.DataRow)
{
int categoryID = int.Parse(gvQuote2.DataKeys[e.Row.RowIndex].Value.ToString());
if (categoryID == 16)
{
GridView gvQuoteItems = e.Row.FindControl("gvMotorQuoteItems") as GridView;
gvQuoteItems.DataSource = _QuoteBLL._GetMotorQuoteItemsDataTable(quote.QuoteID);
gvQuoteItems.DataBind();
}
else
{
GridView gvQuoteItems = e.Row.FindControl("gvQuoteItems") as GridView;
gvQuoteItems.DataSource = _QuoteBLL._GetQuoteItemsDataTable(quote.QuoteID, categoryID);
gvQuoteItems.DataBind();
}
}
When I try to run the above as it is, e.Row.FindControl("gvQuoteItems") always returns null. But if I remove the second ItemTemplate, it works fine. But you see, one of the rows has different columns (gvMotorQuoteItems). How can I go about this?
You cannot override the same template two times. However you can have two placeholeholders within the template and show/hide only the relevant one via Visible property.
<ItemTemplate>
<asp:PlaceHolder ID="phFirst" runat="server">
... pnlQuoteItems
</asp:PlaceHolder>
<asp:PlaceHolder ID="phSecond" runat="server">
... pnlMotorQuoteItems
</asp:PlaceHolder>
</ItemTemplate>

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 disable LinkButton within GridViewclick from Client Side using JavaScript?

I have a GridView, In one column I have LinkButton control. I want to disable click from client side for certain condition on this column. Means for some rows it will not be possible for User to call onclick event and for some rows it is possible.
I want to achieve this from client side using javascript.
Or When User clicks on link, It will notify the User that this action can't be completed for this row.
<asp:GridView Width="100%" ShowHeader="true" ViewStateMode="Enabled" GridLines="Both" CellPadding="10" CellSpacing="5" ID="GridViewMultiplePOSAssociationId" runat="server" AllowSorting="false" AutoGenerateColumns="false" OnRowCommand="RewardGridMultiD_RowCommand"
AllowPaging="true" PageSize="8" OnRowDataBound="grdViewCustomers_OnRowDataBound" PagerSettings-Position="Top" PagerSettings-Mode="NumericFirstLast" PagerSettings-FirstPageText="First" PagerSettings-LastPageText="Last" DataKeyNames="POS Id">
<RowStyle CssClass="table_inner_text" BackColor="WhiteSmoke" BorderColor="CornflowerBlue" Wrap="true" ForeColor="Black" Height="30px" />
<HeaderStyle CssClass="table_head_text" />
<Columns>
<asp:TemplateField ItemStyle-Width="80px">
<ItemTemplate>
<a href="JavaScript:divexpandcollapse('div<%# Eval(" POS Id ") %>');">
<img alt="Details" id="imgdiv<%# Eval("POS Id") %>" src="images/plus.png" />
</a>
<div id="div<%# Eval(" POS Id ") %>" style="display: none;">
<asp:GridView ID="grdViewOrdersOfCustomer" runat="server" AutoGenerateColumns="false" CssClass="ChildGrid">
<RowStyle CssClass="table_inner_text" BackColor="SkyBlue" BorderColor="Black" Wrap="true" ForeColor="White" Height="30px" />
<Columns>
<asp:BoundField ItemStyle-Width="150px" DataField="RULE FILE NAME" HeaderText="RULE FILE NAME" />
<asp:BoundField ItemStyle-Width="150px" DataField="RULE ID" HeaderText="RULE ID" />
<asp:BoundField ItemStyle-Width="150px" DataField="RULE TYPE ID" HeaderText="RULE TYPE ID" />
<asp:BoundField ItemStyle-Width="150px" DataField="START TIME" HeaderText="START TIME" />
<asp:BoundField ItemStyle-Width="150px" DataField="EXPIRY TIME" HeaderText="EXPIRY TIME" />
</Columns>
</asp:GridView>
</div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Width="80px" ItemStyle-Width="80px" ItemStyle-HorizontalAlign="Center" HeaderText="Row Number">
<ItemTemplate>
<asp:Label ID="LabelRowNumberId" runat="server" Text='<%#Eval("Row Number") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Width="80px" ItemStyle-Width="80px" ItemStyle-HorizontalAlign="Center" HeaderText="POS Id">
<ItemTemplate>
<asp:Label ID="LabelPOSID" runat="server" Text='<%#Eval("POS Id") %>'></asp:Label>
<%-- <asp:LinkButton ID="LinkbtnPOSId" CommandArgument='<%#Eval("POS Id") %>' CommandName="ClickPOS" Text='<%#Eval("POS Id") %>' runat="server" CausesValidation="false"></asp:LinkButton>--%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Width="80px" ItemStyle-Width="250px" ItemStyle-HorizontalAlign="Center" HeaderText="Action">
<ItemTemplate>
<asp:LinkButton ID="HyperLinkAssociate" CommandArgument='<%#Eval("POS Id") %>' CommandName="Associate" Text="Associate" runat="server" OnClientClick="return OnClientClickAssociateRewardRuleFile(this);" CausesValidation="false"></asp:LinkButton>/
<asp:LinkButton ID="HyperLinkReplace" CommandArgument='<%#Eval("POS Id") %>' CommandName="Replace" Text="Replace" runat="server" OnClientClick="return OnClientClickReplaceRewardRuleFile(this);" CausesValidation="false"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Width="80px" ItemStyle-Width="250px" ItemStyle-HorizontalAlign="Center" HeaderText="Status">
<ItemTemplate>
<asp:Label runat="server" ID="LabelStatusPendingPOSId" Text='<%#Eval("Status") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
In GridViewMultiplePOSAssociationId there is one column "Status" which has label LabelStatusPendingPOSId, LabelStatusPendingPOSId text is set Applied, Not Applied at the time of Binding. For Rows which has Status Applied, User should not be able to click on LinkButton Associate/Replace else He is allowed to click.
use this code OnRowDataBound for Your Grid
protected void grdViewCustomers_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType==DataControlRowType.DataRow)
{
LinkButton LinkbtnPOSId=(LinkButton)e.Row.FindControl("LinkbtnPOSId");
Label LabelStatusPendingPOSId = (Label)e.Row.FindControl("LabelStatusPendingPOSId");
Boolean boolStatus = LabelStatusPendingPOSId.Text == "Applied" ? true : false;
//LinkbtnPOSId.Attributes.Add("onclick", "function CheckStatus('" + boolStatus.ToString() + "')");
LinkbtnPOSId.Enabled = boolStatus;
}
}
Try this..
You can loop through the Gridview and make the particular control disable...
I am writing the code in javascript pageload function...
function PageLoad(sender, args)
{
for (var i = 0; i <= RowCount; i++)
{
document.getElementById('Gridview1_HyperLinkAssociate_' + i.toString() + '').disabled = true;
}
}
Set RowCount as the number of rows of the Gridview...

Categories

Resources