I want to click on QR Code Annd Fire to gv_SelectedIndexChanged event,
But Not Firing
My Code Below is --Aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterIQMS.master" EnableEventValidation="false" AutoEventWireup="true" CodeFile="SamplePrepration.aspx.cs" Inherits="Reports_SamplePrepration" %> <%@ Register Src="~/Web Controls/CustomPager.ascx" TagName="PagingControl" TagPrefix="uc1" %> <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <script type="text/javascript"> function PrintPanel() { var panel = document.getElementById("<%=panelprint.ClientID %>"); var printWindow = window.open('', '', 'height=400,width=800'); printWindow.document.write('<html><head><title></title>'); printWindow.document.write('</head><body >'); printWindow.document.write(panel.innerHTML); printWindow.document.write('</body></html> <div class="row"> <div class="col-sm-4"> Work Order No <asp:TextBox ID="txtWorkOrderNo" runat="server" OnTextChanged="txtWorkOrderNo_TextChanged" AutoPostBack="true"></asp:TextBox> <asp:HiddenField ID="HiddenField1" runat="server" /> <cc1:AutoCompleteExtender ServiceMethod="SearchWO" MinimumPrefixLength="1" EnableCaching="false" CompletionSetCount="10" TargetControlID="txtWorkOrderNo" ID="AutoCompleteExtender1" runat="server" FirstRowSelected="false" CompletionListCssClass="completionList" CompletionListItemCssClass="listItem" CompletionListHighlightedItemCssClass="itemHighlighted"> </cc1:AutoCompleteExtender> </div> <div class="col-sm-1"> <asp:LinkButton ID="btnInspectionCodeTagging" runat="server" Width="150" class="btn btn-info btn-xs btn-block" OnClick="btnInspectionCodeTagging_Click"><i class="fa-floppy-o"></i> Job Code Tagging</asp:LinkButton> </div> </div> <%-- <asp:Panel ID="pnlContents" runat="server">--%> <div style="overflow: scroll;" onscroll="OnScrollDiv(this)" id="DivMainContent"> <%-- <asp:GridView ID="grdSamplePrep" runat="server" CssClass="table-grid" OnRowDataBound="grdSamplePrep_RowDataBound" OnSelectedIndexChanged="grdSamplePrep_SelectedIndexChanged1"> </asp:GridView>--%> <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder> </div> <%-- </asp:Panel>--%> <%-- <div class="row"> <div class="col-sm-8"> <asp:HiddenField ID="hidPageNo" runat="server" Value="1" /> <uc1:PagingControl ID="gvPager" Visible="false" FirstString="<< First" LastString=" Last >>" NextString="Next >" PrevString="< Prev" TotalNumberPaging="10" OnPaging_Click="gvPager_Paging_Click" runat="server" /> </div> </div>--%> <div id="divPrint" runat="server" title="" style="display: none; text-align: center;max-height: 600px;" class="modalPopup2"> <div class="close"> <asp:ImageButton ID="PopupClose1" runat="server" ImageUrl="~/App_Themes/Images/cross.png" OnClick="PopupClose1_Click" /> </div> <div class="container-fluid" style="text-align: center"> <h2>QR Code Print</h2> <div style="margin: 20px;"> <div class="input-group-append" style="margin-bottom: 20px;"> <asp:Button ID="BtnGenerateQRCode" runat="server" Text="Print QR Code" CssClass="btn btn-primary" OnClientClick="return PrintPanel();" /> </div> <asp:Panel ID="panelprint" runat="server"> <div> <div style="margin: auto;"> <asp:Panel ID="Panel1" runat="server"> <asp:PlaceHolder ID="plBarCode" runat="server" /> <%-- <asp:Label ID="lblmsg" runat="server" />--%> </asp:Panel> </div> </div> </asp:Panel> </div> </div> </div> <div class="modalBackground3" id="modalBackground" runat="server" style="display: none;"> </div>
CS Page
using QRCoder; using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.IO; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class Reports_SamplePrepration : System.Web.UI.Page { SqlConnection con; int PageNum = 1; GridView gv = new GridView(); String strConn = ConfigurationManager.ConnectionStrings["ConOrms"].ConnectionString; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { // ShowData(1); } } protected void grdSamplePrep_RowDataBound(object sender, GridViewRowEventArgs e) { // if (e.Row.RowType == DataControlRowType.DataRow) // { // } } protected void ShowData(int PageNum) { int TotalRecord = 0; // DataTable dt = new DataTable(); int WOID = Convert.ToInt32(ViewState["WoidForBindData"]); DataSet dsSmplPrep = new DataSet(); //WR_TRF.GetTRFReport(BranchID, FromDate, ToDate, Convert.ToInt16(SessionManager.Instance.RoleId),txtTRFno.Text.Trim()); DataTable dtSmplPrep = new DataTable(); try { using (SqlConnection con = new SqlConnection(strConn)) { using (SqlCommand cmd = new SqlCommand("VVS_SAMPLE_PREPARARION", con)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@WOID", SqlDbType.Int).Value = WOID; //cmd.Parameters.Add("@PageSize", SqlDbType.Int).Value = 10; cmd.CommandTimeout = 999999; SqlDataAdapter adp = new SqlDataAdapter(cmd); adp.Fill(dtSmplPrep); } } } catch (Exception ex) { } gv.ID = "EmployeeGridView"; gv.AutoGenerateColumns = false; gv.AllowPaging = true; gv.EnableViewState = true; gv.PageSize = 50; // Default page Size //Create EventHanfler for Paging. // gv.RowDataBound += new GridViewRowEventArgs(this.gv_RowDataBound); gv.SelectedIndexChanged += new EventHandler(gv_SelectedIndexChanged); gv.RowDataBound += new GridViewRowEventHandler(gv_RowDataBound); //gv_RowDataBound(null,null); DataTable dt = new DataTable(); DataTable dt1 = new DataTable(); if (dtSmplPrep != null) { if (dtSmplPrep.Rows.Count > 0) { dt = dtSmplPrep; // DataRow dr = null; if (dt != null) { if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Columns.Count; i++) { BoundField boundField = new BoundField(); boundField.DataField = dt.Columns[i].ColumnName.ToString(); boundField.HeaderText = dt.Columns[i].ColumnName.ToString(); gv.Columns.Add(boundField); // dt1.Columns.Add(new DataColumn(dt.Columns[i].ColumnName, typeof(string))); } } } } } PlaceHolder1.Controls.Add(gv); BindGridView(gv, dt); } static DataTable ListToDataTable<T>(IEnumerable<T> list) { var dt = new DataTable(); foreach (var info in typeof(T).GetProperties()) { dt.Columns.Add(new DataColumn(info.Name, info.PropertyType)); } foreach (var t in list) { var row = dt.NewRow(); foreach (var info in typeof(T).GetProperties()) { row[info.Name] = info.GetValue(t, null); } dt.Rows.Add(row); } return dt; } private void BindGridView(GridView gv, DataTable dt) { gv.DataSource = dt; gv.DataBind(); } protected void gvPager_Paging_Click(object sender, CommandEventArgs e) { } #region AutoComplete Work order No [System.Web.Script.Services.ScriptMethod()] [System.Web.Services.WebMethod] public static List<string> SearchWO(string prefixText, int count) { List<string> customers = new List<string>(); string Item = string.Empty; try { using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConOrms"].ConnectionString)) { using (SqlCommand cmd = new SqlCommand()) { cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "GetWoIdBySearchText"; cmd.Parameters.Add("@SearchText", SqlDbType.NVarChar).Value = prefixText; cmd.Connection = con; con.Open(); using (SqlDataReader sdr = cmd.ExecuteReader()) { while (sdr.Read()) { Item = AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(sdr["JobOrderNo"].ToString(), sdr["WOID"].ToString()); customers.Add(Item); } } con.Close(); } } } catch (Exception ex) { } return customers; } #endregion protected void txtWorkOrderNo_TextChanged(object sender, EventArgs e) { int Woid = 0; //string WONO= txtTextingWO.Text; //GetEditWorkOrder(GetWorkOrderID(WONO)); if (txtWorkOrderNo.Text != string.Empty) { try { string[] FindValue = txtWorkOrderNo.Text.Trim().Split(';'); if (FindValue.Length > 1) { Woid = Convert.ToInt32(FindValue[1].ToString()); ViewState["WoidForBindData"] = Woid; } txtWorkOrderNo.Text = FindValue[0].ToString(); } catch (Exception ex) { } } } protected void btnInspectionCodeTagging_Click(object sender, EventArgs e) { ShowData(1); } protected void gv_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { int index = e.Row.RowIndex; int indexcell = e.Row.Cells.Count - 1; for (int j = 4; j <= indexcell; j++) { PlaceHolder pl = new PlaceHolder(); pl.ID = e.Row.Cells[j].Text; if (e.Row.Cells[j].Text != " ") { e.Row.Cells[j].Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(gv, "Select$" + e.Row.RowIndex); e.Row.Cells[j].Attributes["style"] = "cursor:pointer"; string code = e.Row.Cells[j].Text; QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(code, QRCodeGenerator.ECCLevel.Q); QRCode qrCode = new QRCode(qrCodeData); System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image(); imgBarCode.Height = 60; imgBarCode.Width = 60; using (Bitmap bitMap = qrCode.GetGraphic(20)) { using (MemoryStream ms = new MemoryStream()) { bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png); byte[] byteImage = ms.ToArray(); imgBarCode.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(byteImage); } pl.Controls.Add(imgBarCode); } } e.Row.Cells[j].Controls.Add(pl); } } } protected void gv_SelectedIndexChanged(object sender, EventArgs e) { int index = gv.SelectedRow.RowIndex; //Accessing TemplateField Column controls. // string lblJobCode = ( gv.SelectedRow.FindControl("lblJobCode") as Label).Text; string code = index.ToString(); ShowData(1); // Response.Redirect("Reports/QRCodePrint.aspx?index=" + index + "&code=" + code.ToString()); modalBackground.Attributes.Add("style", "display:block"); divPrint.Attributes.Add("style", "display:block"); QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(code, QRCodeGenerator.ECCLevel.Q); QRCode qrCode = new QRCode(qrCodeData); System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image(); imgBarCode.Height = 200; imgBarCode.Width = 200; using (Bitmap bitMap = qrCode.GetGraphic(20)) { using (MemoryStream ms = new MemoryStream()) { bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png); byte[] byteImage = ms.ToArray(); imgBarCode.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(byteImage); } plBarCode.Controls.Add(imgBarCode); } //lblmsg.Text = QRCode; } protected void grdSamplePrep_SelectedIndexChanged1(object sender, EventArgs e) { } protected void PopupClose1_Click(object sender, ImageClickEventArgs e) { ShowData(1); modalBackground.Attributes.Add("style", "display:none"); divPrint.Attributes.Add("style", "display:none"); } }