Click here to Skip to main content
16,018,442 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have used a gridview to get all the questions selected by a particular user to fill the slambook...

There is a textbox for each question where you would type your answers and at the end there is a button outside gridview named "post slambook"

on click of button "post slambook"
C#
prpobj.useridto = Convert.ToInt32(Request.QueryString["uid"]);
prpobj.useridfrom = Convert.ToInt32(Session["user_id"]);
DataTable dtbl=mainobj.getslambooksentstatus(prpobj);
if(dtbl.Rows.Count==0)
{
    int i;
    int j = gvpostslambook.Rows.Count;
    for (i = 0; i < j; i++)
    {
        GridViewRow row = (GridViewRow)gvpostslambook.Rows[i];
        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);
    }
    lblmsg.Text = "Slambook sent";
    Response.Redirect("~/User/Slambook_Sent_Status.aspx");
}
else
{
    lblmsg.Text = "You have already filled this person's slambook";
}

It is getting the value of the question id which is i am getting from the linkbutton's command argument...

but it is not getting the value of the textbox..

any one know what is the problem?...
Posted
Updated 17-Feb-10 2:36am
v23

use for each loop it will be easier to get the values from respective gridviewrow. It will definitely work.

for each(grdviewrow grv in gvpostslambook.rows
{
  textbox txtanswer=grv.findcontrol("txt");
  prpobj.answer = txtanswer.Text.Trim();
  mainobj.postslambook(prpobj);
}
lblmsg.Text = "Slambook sent";
Response.Redirect("~/User/Slambook_Sent_Status.aspx");
}
else
{
   lblmsg.Text = "You have already filled this person's slambook";
}
 
Share this answer
 
v2
Please check if you are getting Text box ? If you are getting the linkbutton's command argument then you must get value of textbox
 
Share this answer
 
Try to get the reference to the textbox in the Row command Event handler of the GridView. but for that you have to set the command name property of the button.
 
Share this answer
 
Then there would be a chance that you during postback rebinds the grid and because of that you are not getting the values, i suppose. And it is obvious that u r assinging the values of questionid at same time so you are getting linkbutton values right. i think this is the issue

.....

please let me know if this is the situation ....

thanks
 
Share this answer
 

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