protected void Page_Load(object sender, EventArgs e) { Onlyread(); { int rowIndex = 0; SqlConnection conn = new SqlConnection(connectionString); StringBuilder sb = new StringBuilder(string.Empty); try { int count = GridView2.Rows.Count; for (int i = 0; i < count; i++) { TextBox box11 = (TextBox)GridView2.Rows[rowIndex].Cells[0].FindControl("TextBox11"); TextBox box13 = (TextBox)GridView2.Rows[rowIndex].Cells[1].FindControl("TextBox13"); rowIndex++; box11.ReadOnly = true; box13.ReadOnly = true; } } catch (System.Data.SqlClient.SqlException ex) { string msg = "Error:"; msg += ex.Message; throw new Exception(msg); } } } protected void BtnSave_Click(object sender, EventArgs e) { OnlyRead(); }
protected void Page_Load(object sender, EventArgs e) { if (Page.IsPostBack) { OnlyRead(); } } private void Onlyread() { int rowIndex = 0; SqlConnection conn = new SqlConnection(connectionString); StringBuilder sb = new StringBuilder(string.Empty); try { int count = GridView2.Rows.Count; for (int i = 0; i < count; i++) { TextBox box11 = (TextBox)GridView2.Rows[rowIndex].Cells[0].FindControl("TextBox11"); TextBox box13 = (TextBox)GridView2.Rows[rowIndex].Cells[1].FindControl("TextBox13"); rowIndex++; box11.ReadOnly = true; box13.ReadOnly = true; } } catch (System.Data.SqlClient.SqlException ex) { string msg = "Error:"; msg += ex.Message; throw new Exception(msg); } } } protected void BtnSave_Click(object sender, EventArgs e) { OnlyRead(); }
protected void Page_Load(object sender, EventArgs e) { if (Page.IsPostBack) { OnlyRead(); } } and write your onlyread() method and just call it from btnclick. protected void BtnSave_Click(object sender, EventArgs e) { OnlyRead(); }
protected void Page_Load(object sender, EventArgs e) { BtnSave_Click(null,null); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)