Monday, March 26, 2012

Updating GridView ,

Hi All,

I am having a problem in updating my GridView partially (AJAX). Here is my scenario.
I have 2 UpdatePanel. (DisplayUpdatePanel and EditUpdatePanel)

Inside "DisplayUpdatePanel" i have 1 GridView which shows my data from my database. i'm using XML schema DataSet and ObjectDataSource to bound data to my gridview
SelectMethod runs perfectly.

Inside "EditUpdatePanel" i have some textboxes, and links buttons (Update,Delete,New) and one HTML Editor.

The way it works as follow:

1. If one row is selected in "DisplayUpdatePanel" then My "EditUpdatePanel" will get updated with the same values from "DisplayUpdatePanel" automatically.

2. Inside my "EditUpdatePanel", i can edit all the values.

3. Once i finished, i can click "Update" link button to execute my Update Stored procedure. which i Typed it manually instead of being autogenerated by the wizard.

Update Stored Procedure runs perfectly as i expected.

My problem here is that my "DisplayUpdatePanel" doesnt update automatically once the data has been updated.

anyone know how to solve my problem?


below are my triggers from both UpdatePanel.

"DisplayUpdatePanel"

<Triggers>
<asp:AsyncPostBackTrigger ControlID="LNK_UPDATE" EventName="DataBinding" />
</Triggers>

"EditUpdatePanel"

<Triggers>
<asp:AsyncPostBackTrigger ControlID="DisplayUpdatePanel" EventName="SelectedIndexChanged" />
</Triggers>

Thank You Very Much

On3

<Triggers>
<asp:AsyncPostBackTrigger ControlID="LNK_UPDATE" EventName="Click" />
</Triggers>


Thank yourmaiya for your reply.

I've tried your solution, but still not my gridview is still the same. it doesn't update by itself ...
is there any relation with my multiview?

because i put all my update panels inside one of the views.
thanks



Once you update GridView in server with your StoredProcedure then call DisplayUpdatePanel.Update();


Assuming that you have done what was previously suggested, that is, ensure the UpdatePanel's children are rendered via invoking the Update() method. I also found that disabling view state on the GridView solves some issues with the GV updating after an asyn postback. Hope this helps.


Hi Amit, thank you for your reply :)

my DisplayUpdatePanel still doesnt update its content by itself...
What do you mean by "Update GridView in Server" ... because, as far as i understand,
my scenario is actually updating the database directly through my StoredProcedure.

below is my snippet for updating my data.

protected void UpdateArticle()
{
MyConn = new Connection();
DateTime CurrDate = DateTime.Now; // Get the Current Date and Time.
SqlCommand SqlCmd = new SqlCommand("Article_Update", MyConn.GetConnection());
SqlCmd.CommandType = CommandType.StoredProcedure;

Label ArticleID = (Label) GridView3.SelectedRow.FindControl("Label2");

SqlCmd.Parameters.AddWithValue("@.Title", TXT_ArticleTitle.Text);
SqlCmd.Parameters.AddWithValue("@.Cat_Id", Convert.ToInt32(DRP_FileUnder.SelectedItem.Text));
SqlCmd.Parameters.AddWithValue("@.Content", FCKeditor.Value);
SqlCmd.Parameters.AddWithValue("@.Summary", TXT_Summary.Text);
SqlCmd.Parameters.AddWithValue("@.Original_ArticleID", Convert.ToInt32(ArticleID.Text));

if (MyConn.isConnected() == false)
MyConn.Connect();

SqlCmd.ExecuteNonQuery();
MyConn.CloseConnection();

}

is there any more clues for my case ?

thank you Amit



on3_cool:

protected void UpdateArticle()
{
MyConn = new Connection();
DateTime CurrDate = DateTime.Now; // Get the Current Date and Time.
SqlCommand SqlCmd = new SqlCommand("Article_Update", MyConn.GetConnection());
SqlCmd.CommandType = CommandType.StoredProcedure;

Label ArticleID = (Label) GridView3.SelectedRow.FindControl("Label2");

SqlCmd.Parameters.AddWithValue("@.Title", TXT_ArticleTitle.Text);
SqlCmd.Parameters.AddWithValue("@.Cat_Id", Convert.ToInt32(DRP_FileUnder.SelectedItem.Text));
SqlCmd.Parameters.AddWithValue("@.Content", FCKeditor.Value);
SqlCmd.Parameters.AddWithValue("@.Summary", TXT_Summary.Text);
SqlCmd.Parameters.AddWithValue("@.Original_ArticleID", Convert.ToInt32(ArticleID.Text));

if (MyConn.isConnected() == false)
MyConn.Connect();

SqlCmd.ExecuteNonQuery();
MyConn.CloseConnection();

DisplayUpdatePanel.Update();

}


Hi AMit,

i still cannot use the "DisplayUpdatePanel.Update()" for my case.
however, i found the solution by my self.
here is what i have done.
1. Instead of executing my UpdateStored Procedure directly as the link button click, i attached my stored procedure into my ObjectDataSet.
2. Then i set the default value of each my "UpdateParameters" in ObjecDataSource onto the appropriate controlId.Text
3. In My protected void LNK_UPDATE_Click(object sender, EventArgs e) , i just call my function which executes the ObjectDataSource update command.

The snippet as follows.

protected void LNK_UPDATE_Click(object sender, EventArgs e)
{
UpdateArticle(); // Execute UpdateCommand.
ClearALLValues(); // Clear All values in the forms.
SetButtonsIn_EditPanel(false, false); // Set Appropriate buttons.
}

protected void UpdateArticle()
{
try
{
Admin_ArticlesODS.Update();
}
catch (System.Reflection.TargetInvocationException error)
{
FCKeditor.Value = error.ToString(); // Display error catch by the TargetIncovationExection to the editor
}

}

Hopefully It helps.

No comments:

Post a Comment