I have a report in the form of a DataGrid. The users want to be able to Sort the DataGrid AND be able to add a Comment to records when necessary.
The problem I am running into is, once the user inputs text to the editable field and clicks Update, the page refreshes to the pre-Update state, i.e. the Comment field is still a TextBox, but the user input is gone, and the TextBox reverts to whatever text it presented when Edit was clicked.
I think I am running into ViewState here, but I can't disable(?) ViewState because I need it to sort columns.
Any ideas what I should do next?
BTW, when the user clicks Update, it DOES create a Comment Record, but it sets the Comment column to '' (the value in the comment field after the textbox is refreshed.)
If it helps any, here is the _Update code:
----------------
protected void dgShipping_Update(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
try
{
if (SqlMethods.doesCommentRecordExist(e.Item.Cells[0].Text) == false)
{
int insertRecord = doInsert(e.Item.Cells[0].Text, ((System.Web.UI.WebControls.TextBox)e.Item.Cells[15].Controls[0]).Text);
if (insertRecord != 1)
{
lblError.Text = "Error creating record " + e.Item.Cells[0].Text + ".";
}
else
{
dgShipping.DataBind();
dgShipping.EditItemIndex = -1;
}
}
else
{
int updateRecord = doUpdate(e.Item.Cells[0].Text, ((System.Web.UI.WebControls.TextBox)e.Item.Cells[15].Controls[0]).Text);
if (updateRecord != 1)
{
lblError.Text = "Error updating record " + e.Item.Cells[0].Text + ".";
}
else
{
dgShipping.DataBind();
dgShipping.EditItemIndex = -1;
}
}
}
catch (Exception err)
{
lblError.Text = err.Message;
}
}
protected int doUpdate(string RecordID, string CommentText)
{
return SqlMethods.updateExistingComment(RecordID, CommentText);
}
protected int doInsert(string RecordID, string CommentText)
{
return SqlMethods.addNewComment(RecordID, CommentText);
}
The problem I am running into is, once the user inputs text to the editable field and clicks Update, the page refreshes to the pre-Update state, i.e. the Comment field is still a TextBox, but the user input is gone, and the TextBox reverts to whatever text it presented when Edit was clicked.
I think I am running into ViewState here, but I can't disable(?) ViewState because I need it to sort columns.
Any ideas what I should do next?
BTW, when the user clicks Update, it DOES create a Comment Record, but it sets the Comment column to '' (the value in the comment field after the textbox is refreshed.)
If it helps any, here is the _Update code:
----------------
protected void dgShipping_Update(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
try
{
if (SqlMethods.doesCommentRecordExist(e.Item.Cells[0].Text) == false)
{
int insertRecord = doInsert(e.Item.Cells[0].Text, ((System.Web.UI.WebControls.TextBox)e.Item.Cells[15].Controls[0]).Text);
if (insertRecord != 1)
{
lblError.Text = "Error creating record " + e.Item.Cells[0].Text + ".";
}
else
{
dgShipping.DataBind();
dgShipping.EditItemIndex = -1;
}
}
else
{
int updateRecord = doUpdate(e.Item.Cells[0].Text, ((System.Web.UI.WebControls.TextBox)e.Item.Cells[15].Controls[0]).Text);
if (updateRecord != 1)
{
lblError.Text = "Error updating record " + e.Item.Cells[0].Text + ".";
}
else
{
dgShipping.DataBind();
dgShipping.EditItemIndex = -1;
}
}
}
catch (Exception err)
{
lblError.Text = err.Message;
}
}
protected int doUpdate(string RecordID, string CommentText)
{
return SqlMethods.updateExistingComment(RecordID, CommentText);
}
protected int doInsert(string RecordID, string CommentText)
{
return SqlMethods.addNewComment(RecordID, CommentText);
}