I have Server side Created Gridview ,which i want fire select Index Changed Event
MY code is
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.Attributes.Add("AutoPostback", "true"); 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 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); }