public static void AddNewRowSingleColumn(int OpCode, string SpName, ref GridView dg, ref bool k_blnIsAddingNew, ref HtmlGenericControl DivError, ref Label _LblError) { string g_strErrorMessage = ""; try { DataTable GridTable = GeneralBL.FillDataGrid(OpCode, SpName, ref g_strErrorMessage, ""); //if ((GridTable.Rows.Count == 0) || (GridTable == null)) //{ // DataRow dr = GridTable.NewRow(); // GridTable.Rows.Add(dr); // dg.DataSource = GridTable; // dg.DataBind(); //} DataRow NewRow = GridTable.NewRow(); Label lblName = new Label(); if (dg.Rows.Count == 0) { lblName.Text = ""; } /************************************************************ * Here We have Two Options If the User is on First Pasge then */ //Label lblName = (Label)dg.Rows[0].FindControl(ControlName); int nNewItemIndex = dg.Rows.Count; if (nNewItemIndex < dg.PageSize) { if (lblName.Text == "") { dg.EditIndex = nNewItemIndex; } else { dg.EditIndex = nNewItemIndex; } } else { int r = GridTable.Rows.Count; int m_pageNumber = r / nNewItemIndex; dg.PageIndex = m_pageNumber; r = (r - nNewItemIndex * m_pageNumber); dg.EditIndex = r; } GridTable.Rows.Add(NewRow); GridTable.AcceptChanges(); dg.DataSource = GridTable; dg.DataBind(); k_blnIsAddingNew = true; } catch (Exception exp) { DivError.Visible = true; _LblError.Text = exp.Message; } }
// Fill Grid New Version public static void FillDirectGrid(int OpCode, string _spName, ref HtmlGenericControl DivError, ref Label _LblError, ref GridView dg, ref int k_intTotalRowsNumbers, int EditCol, int delcol) { try { string g_strErrorMessage = ""; DivError.Visible = false; _LblError.Text = ""; dg.DataSource = null; dg.DataBind(); DataTable dt = GeneralBL.FillDataGrid(OpCode, _spName, ref g_strErrorMessage, "2"); if (g_strErrorMessage.Length < 1) { if (GeneralBL.isdtEmptyNull(dt) == true) { if (EditCol != -1) { dg.Columns[EditCol].Visible = true; } if (delcol != -1) { dg.Columns[delcol].Visible = true; } k_intTotalRowsNumbers = dt.Rows.Count; } dg.DataSource = dt; dg.DataBind(); } else { DivError.Visible = true; _LblError.Text = g_strErrorMessage.Replace("Error : ", ""); } } catch (Exception exp) { DivError.Visible = true; _LblError.Text = exp.Message; } }