So the problem is i don't get get a value from textbox field on GridView RowUpdating event.
Here is HTML ASP.net code:
<%-- <asp:LinkButton ID="Button_delete" runat="server" CausesValidation="false" CommandName="delete" CssClass="btn btn-xs btn-danger" ToolTip="Izbriši"> --%>
And here is code behind:
protected void Grid_Reload(int i)
{
DB db = new DB();
if (i == 0 || i == 1)
{
SqlDataSource1.ConnectionString = db.GetConnString();
GridView1.DataBind();
}
if (i == 0 || i == 2)
{
SqlDataSource2.ConnectionString = db.GetConnString();
GridView2.DataBind();
}
if (i == 0 || i == 3)
{
SqlDataSource3.ConnectionString = db.GetConnString();
GridView3.DataSource = SqlDataSource3;
GridView3.DataBind();
}
}
protected void GridView3_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
String warning_msg = "", error_msg = "", info_msg = "", success_msg = "";
int i = 0;
Commons cm = new Commons();
try
{
GridViewRow row = (GridViewRow)GridView3.Rows[e.RowIndex];
int periodid = Convert.ToInt32(GridView3.DataKeys[e.RowIndex].Values[0]);
string workerid = GridView3.DataKeys[e.RowIndex].Values[1].ToString();
TextBox field1 = (TextBox)row.Cells[2].Controls[0];
String SQL = "update _utJN_EvidencaDCSum set acReason = '" + field1.Text + "' where anPeriodID = '" + periodid.ToString() + "' and acWorkerID = '" + workerid + "'";
DB db = new DB();
db.ExecSQL(SQL);
GridView3.EditIndex = -1;
Grid_Reload(3);
}
catch (Exception ex)
{
error_msg = ex.Message;
}
finally
{
i = cm.SetMessage(LabelError, error, error_msg, LabelWarning, warning, warning_msg, LabelInfo, info, info_msg, LabelSuccess, success, success_msg);
}
if (i == 1)
{
ClientScript.RegisterStartupScript(this.GetType(), "hash", "location.hash = '#msg';", true);
}
}
protected void GridView3_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView3.EditIndex = e.NewEditIndex;
Grid_Reload(3);
}
protected void GridView3_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
Grid_Reload(3);
}
The problem is I assume here:
TextBox field1 = (TextBox)row.Cells[2].Controls[0];
But I cannot figure it out. I have almost identical example, but it's working perfectly.
Other method (that one is working just fine):
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
String warning_msg = "", error_msg = "", info_msg = "", success_msg = "";
int i = 0;
Commons cm = new Commons();
try
{
GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
int id = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values[0]);
TextBox field1 = (TextBox)row.Cells[1].Controls[0];
String SQL = "update _utJN_Holidays set acText = '" + field1.Text + "' where anID = '" + id.ToString()+ "'";
DB db = new DB();
db.ExecSQL(SQL);
GridView1.EditIndex = -1;
Grid_Reload();
}
catch (Exception ex)
{
error_msg = ex.Message;
}
finally
{
i = cm.SetMessage(LabelError, error, error_msg, LabelWarning, warning, warning_msg, LabelInfo, info, info_msg, LabelSuccess, success, success_msg);
}
if (i == 1)
{
ClientScript.RegisterStartupScript(this.GetType(), "hash", "location.hash = '#msg';", true);
}
}
I tried also this:
//Loop through all Cells in the Row.
int index = 0;
foreach (TableCell cell in row.Cells)
{
if (cell.Controls.Count > 0)
{
//Check whether Cell has TextBox.
if (cell.Controls[0] is TextBox)
{
//Reference the TextBox.
TextBox textBox = cell.Controls[0] as TextBox;
textBox.ID = "txtReason";
//warning_msg += "xx" + GridView3.HeaderRow.Cells[index].Text + "xx" + index.ToString();
}
}
index++;
}
//TextBox field1 = (TextBox)row.Cells[2].Controls[0];
TextBox field1 = (TextBox)row.FindControl("txtReason");
String SQL = "update _utJN_EvidencaDCSum set acReason = '" + field1.Text + "' where anPeriodID = '" + periodid.ToString() + "' and acWorkerID = '" + workerid + "'";
and its still empty..
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)