Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to update multiple rows on click of the button used outside the gridview???



where each row in gridview is having

1. A question- (which is binded from the database)
2. an answer- (for this a textbox is used)


i have searched on google but with no results..


how can it be done??

if someone can help???

thanks regards....

foreach (GridViewRow row in gvpostslambook.Rows)
{
LinkButton lbtnpostslambook = (LinkButton)row.FindControl("lbtnargument");
TextBox txtanswer = (TextBox)row.FindControl("txt");
prpobj.questionid = Convert.ToInt32(lbtnpostslambook.CommandArgument);
prpobj.answer = txtanswer.Text.Trim();
mainobj.postslambook(prpobj);
}


the value for the prp.questionid is comming for each row in gridview but the value of the textbox is not comming....

and thanks that you answered me....

but my friend
thatraja
i am not getting the values of the textbox from the database..
i am just using the textboxes to insert the answers for the corresponding
questions...

your code showing that i should bind the text to the textbox in the loop from the database but i am getting nothing from the database except those questions....

i still do not know whats the problem with my code!!!
Posted
Updated 22-Feb-10 5:44am
v15

|steeve_richard wrote

|and plz if you can tell me how to edit my post..
|then tell because i can only see improve question link..


that's the link for editing your post.

For Your issue

For template items in gridview, once you did databind then you should assign the values through loop.
example
gvEmp.DataSource = dtEmployee;
gvEmp.DataBind();
for (int i = 0; i < dtEmployee.Rows.Count; i++)
{
 for (int j = 1; j < dtEmployee.Columns.Count; j++)
 {
  if (j == 1 || j == 2 || j == 3)
  {
   ((TextBox)(gvEmp.Rows[i].Cells[j].Controls[1])).Text = dtEmployee.Rows[i][j].ToString();
  }
 }
}
so change the code based on your need
 
Share this answer
 
The most logical way to do this, is to modify your data source to contain the new data, and then rebind.



You should edit your post, not post fake 'answers'.

Where-ever your data comes from, you need to update it to include the rows you want, then bind the data with the new rows. I don't understand how this code is related to your question.

If the answers do not come from your db, why are you binding them to a grid ? In that case, you should create a collection of questions with answers, build it in memory, and bind to that.
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900