<asp:GridView runat="server" ID="TaxGV" DataKeyNames="Id, BookTaxId" AutoGenerateColumns="false" OnDataBound="TaxGV_DataBound" OnRowCommand="TaxGV_RowCommand" CssClass="table table-bordered table-hover table-responsive" ShowFooter="true">
public void LoadTaxGridView_Table() { double Value = 0; int bkId = Convert.ToInt32(bookId); string str = ConfigurationManager.ConnectionStrings["ConStr"].ConnectionString; SqlConnection con = new SqlConnection(str); con.Open(); SqlCommand cmd = new SqlCommand("select b.BookTaxId as BookTaxId, b.TaxId as Id, t.Name as Name, b.TaxValue as Value from BookingTax as b inner join Taxes as t on t.Id = b.TaxId where b.BookingId=@BookingId and b.Is_Delete=0", con); cmd.Parameters.AddWithValue("@BookingId", bkId); DataTable dt_BookTax = new DataTable(); SqlDataReader reader = cmd.ExecuteReader(); dt_BookTax.Load(reader); con.Close(); foreach(DataRow row in dt_BookTax.Rows) { int Id = Convert.ToInt32(row["BookTaxId"]);//This gives correct Value of BookTaxId Value = Convert.ToDouble(row["Value"]); total_tax_Amount += (temp_Amount * Value / 100); } ViewState["BookTax_Table"] = dt_BookTax; TaxGV.DataSource = dt_BookTax; TaxGV.DataBind(); TaxGV.Rows[TaxGV.Rows.Count - 1].Visible = false; }
public void Edit_Booking_Tax() { int bkId = Convert.ToInt32(bookId); string str = ConfigurationManager.ConnectionStrings["ConStr"].ConnectionString; SqlConnection con = new SqlConnection(str); con.Open(); foreach(GridViewRow row in TaxGV.Rows) { int rowindex = row.RowIndex; int BookTaxId = Convert.ToInt32(TaxGV.DataKeys[rowindex].Values["BookTaxId"]); //This BookTaxId gives value=1; } }
Edit_Booking_Tax()
foreach
foreach(GridViewRow row in TaxGV.Rows) { int BookTaxId = Convert.ToInt32(row.Cells[0].Text); //I already test and is working }
DataKey
froeach
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)