在gridview中插入多行

在gridview中插入多行

本文介绍了在gridview中插入多行???的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何单击gridview外部使用的按钮来更新多行??



gridview中的每一行都具有

1.一个问题-(从数据库绑定)
2.一个答案-(为此使用一个文本框)


我已经在Google上搜索过,但没有结果..


怎么做?

如果有人可以提供帮助??

谢谢问候....

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



prp.questionid的值在gridview中的每一行都出现了,但是文本框的值没有出现....

并感谢您回答了我....

但是我的朋友
撒拉雅
我没有从数据库中获取文本框的值..
我只是在使用文本框插入相应的答案
问题...

您的代码显示我应该从数据库中将文本绑定到循环中的文本框,但是除了那些问题之外,我没有从数据库中得到任何东西....

我仍然不知道我的代码有什么问题!!!



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!!!

推荐答案

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



这篇关于在gridview中插入多行???的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 18:00