如何解决我的问题 [英] How to resolve my problem
本文介绍了如何解决我的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面的代码行未从网格
string temp2 = grdView.Rows[i].Cells[3].Text;
<itemtemplate>
<asp:Label ID="lblComments" runat="server" Text='<%# Bind("Comments") %>'>
<asp:TextBox ID="txtComments" runat="server">
</itemtemplate>
代码行下方未从网格
Below line of code not taken values from grid
string temp2 = grdView.Rows[i].Cells[3].Text;
protected void btnUpdae_Click(object sender, EventArgs e)
{
string connection = System.Configuration.ConfigurationManager.ConnectionStrings["QuestionnaireConnection"].ConnectionString;
using (SqlConnection con = new SqlConnection(connection))
{
con.Open();
if (grdView.Rows.Count > 0) //[here the row count is zero
{
foreach (GridViewRow row in grdView.Rows) //[if I have break point here I am not getting into the loop]
{
for (int i = 0; i < grdView.Rows.Count; i++)
{
Question qs = new Question();
string name = Request.QueryString["UserName"];
string temp1 = grdView.Rows[i].Cells[0].Text;
string temp2 = grdView.Rows[i].Cells[3].Text;
SqlDataAdapter da;
da = new SqlDataAdapter("UPDATE Questionnaire_UserAnswers SET Comments='" + temp2 + "' WHERE Question_ID=" + temp1 + "", con);
DataSet ds = new DataSet();
da.Fill(ds);
grdView.DataSource = ds;
}
grdView.EditIndex = -1;
ShowGridBindData();
lblmessage.Visible = true;
lblmessage.Text = "Record Updated Successfully";
}
}
推荐答案
使用数据键更好地获取网格值
gridview.DataKeys(e.RowIndex).Values(0).ToString()
use data keys is better to get grid values
gridview.DataKeys(e.RowIndex).Values(0).ToString()
这是查找控件和文本值的方法
在这里我们可以使用Dropdown或任何控件
GridviewRow行;
This is the way to find Control And Text value
here we can use Dropdown or any control
GridviewRow row;
string textBoxText = _
((TextBox)row.FindControl("TextBox1")).Text;
使用findbycontrol
如果您使用模板字段
use findbycontrol
if you use template fields
这篇关于如何解决我的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文