GridView 2.0
<EditItemTemplate> . . . <EditItemTemplate>
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /> <EditRowStyle BackColor="#999999" />
Code: #region Page load event protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { // Here binding data to the Grid. BindAllTaxData(); } } #endregion
#region Bind All Tax Master Data private void BindAllTaxData() { // Calling Database function here and asign to dataset. if (dsTaxMaster.Tables[0].Rows.Count > 0) { grdTaxMaster.DataSource=dsTaxMaster.Tables[0]; grdTaxMaster.DataBind(); grdTaxMaster.Columns[grdTaxMaster.Columns.Count - 1].Visible = true; } else { // Binding Empty DataTable to the Grid otherwise footer will not visible.
DataTable dtTable = new DataTable(); dtTable.Columns.Add("TAX_ID"); dtTable.Columns.Add("TAX_CODE"); dtTable.Columns.Add("TAX_NAME"); dtTable.Columns.Add("TAX_PERCENTAGE"); dtTable.Columns.Add("TAX_STATUS", typeof(System.Boolean)); DataRow dr = dtTable.NewRow(); dr["TAX_STATUS"] = false; dtTable.Rows.Add(dr); grdTaxMaster.DataSource = dtTable; grdTaxMaster.DataBind(); grdTaxMaster.Columns[grdTaxMaster.Columns.Count - 1].Visible = false; grdTaxMaster.Rows[0].Cells[4].Controls[1].Visible = false; }
} #endregion
#region Gridview Row Editing Event protected void grdTaxMaster_RowEditing(object sender, GridViewEditEventArgs e) { grdTaxMaster.EditIndex = e.NewEditIndex; BindAllTaxData(); } #endregion #region GridView Row Canceling Edit Event protected void grdTaxMaster_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { grdTaxMaster.EditIndex = -1; BindAllTaxData(); } #endregion #region GridView Row Updating Event protected void grdTaxMaster_RowUpdating(object sender, GridViewUpdateEventArgs e) { int TaxId = Convert.ToInt32(grdTaxMaster.DataKeys[e.RowIndex].Value.ToString()); TextBox txtTaxCode = (TextBox)grdTaxMaster.Rows[e.RowIndex].FindControl("txtTaxCode"); TextBox txtTaxName = (TextBox)grdTaxMaster.Rows[e.RowIndex].FindControl("txtTaxName"); TextBox txtTaxPercentage = (TextBox)grdTaxMaster.Rows[e.RowIndex].FindControl("txtTaxPercentage"); CheckBox chkTaxStatus = (CheckBox)grdTaxMaster.Rows[e.RowIndex].FindControl("chkTaxStatus"); // Call Database update Event here
//…… … //………. // BindAllTaxData(); } #endregion #region GridView Row Command Event for Insert Row protected void grdTaxMaster_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Add") { TextBox txtFooterTaxCode = (TextBox)grdTaxMaster.FooterRow.FindControl("txtFooterTaxCode"); TextBox txtFooterTaxName = (TextBox)grdTaxMaster.FooterRow.FindControl("txtFooterTaxName"); TextBox txtFooterTaxPercentage = (TextBox)grdTaxMaster.FooterRow.FindControl("txtFooterTaxPercentage"); CheckBox chkTaxStatus = (CheckBox)grdTaxMaster.FooterRow.FindControl("chkFooterTaxStatus"); // Call Database Insert Event here //…… … //………. // BindAllTaxData(); } } #endregion
#region GridView Page Index Changing Event protected void grdTaxMaster_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
grdTaxMaster.PageIndex = e.NewPageIndex; BindAllTaxData();
} #endregion