获取在gridview中使用的文本框的值时出现问题 [英] problem getting the value of textbox used in gridview

查看:135
本文介绍了获取在gridview中使用的文本框的值时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用gridview来获取特定用户选择的所有问题来填满填空书...

每个问题都有一个文本框,您可以在其中输入答案,最后在gridview外部有一个名为"post slambook"的按钮.

在按钮"post slambook"上单击

 prpobj.useridto = Convert.ToInt32(Request.QueryString [" ]);
prpobj.useridfrom = Convert.ToInt32(Session [" ]);;
数据表dtbl = mainobj.getslambooksentstatus(prpobj);
如果(dtbl.Rows.Count ==  0 )
{
     int  i;
     int  j = gvpostslambook.Rows.Count;
     for (i =  0 ; i ><  j; i ++)
    {
        GridViewRow row =(GridViewRow)gvpostslambook.Rows [i];
        LinkBut​​ton lbtnpostslambook =(LinkBut​​ton)row.FindControl(" );
        TextBox txtanswer =(TextBox)row.FindControl(" );
        prpobj.questionid = Convert.ToInt32(lbtnpostslambook.CommandArgument);
        prpobj.answer = txtanswer.Text.Trim();
        mainobj.postslambook(prpobj);
    }
    lblmsg.Text = " ;
    Response.Redirect(" );
}
其他
{
    lblmsg.Text = " ;
} 


它正在获取问题id的值,这是我从linkbutton的命令参数中获取的...

但是它没有获得文本框的值..

任何人都知道这是什么问题吗?...

解决方案

在每个循环中使用,从相应的gridviewrow获取值将更加容易.它肯定会工作.

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";
}


请检查您是否收到文本框?如果要获取linkbutton的命令参数,则必须获取文本框的值

尝试在GridView的Row命令事件处理程序中获取对该文本框的引用.但是为此,您必须设置按钮的命令名称属性.


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"

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?...

解决方案

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";
}


Please check if you are getting Text box ? If you are getting the linkbutton''s command argument then you must get value of textbox


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.


这篇关于获取在gridview中使用的文本框的值时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆