Sandeep Kumar

Sandeep Kumar

  • 1.1k
  • 683
  • 59.4k

Gridview select index chnaged event not firing,why

Jan 9 2023 5:28 AM

I have Server side gridview,through which i  want to fire Select Index change devent not firing,Tried every possible step but not found solution

My Code--

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);
}
 

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;

}

Answers (3)