0

我正在尝试将单元格数据检索到文本框,当我在网格视图中选择任何行时会发生这种情况,文本框将采用新值

我已经启用auto post back了文本框

这是我的代码

protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
{

    TextBox3.Text = GridView2.Rows[GridView2.SelectedIndex].Cells[2].Text;
}

但是,语法没有错误,它没有在文本框中检索任何东西,有什么建议吗?

我在用

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data.Sql;

我在 C# 工作,Visual Studio 2010 Express Web 开发人员

4

2 回答 2

3

从 VS 2010 文档中,我建议首先检查行和单元格是否不为空。

// Get the currently selected row using the SelectedRow property.
GridViewRow row = CustomersGridView.SelectedRow;

// Display the company name from the selected row.
// In this example, the third column (index 2) contains
// the company name.
MessageLabel.Text = "You selected " + row.Cells[2].Text + ".";
于 2010-12-22T16:06:05.163 回答
0
 protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
{
    Panel1.Visible = true;

    if (GridView2.SelectedIndex == 0)
    {
        webspace.Text = GridView2.Rows[GridView2.SelectedIndex].Cells[1].Text;
        Bandwidth.Text = GridView2.Rows[GridView2.SelectedIndex].Cells[2].Text;
        Email.Text = GridView2.Rows[GridView2.SelectedIndex].Cells[3].Text;
        FTP.Text = GridView2.Rows[GridView2.SelectedIndex].Cells[4].Text;
        Subdomain.Text = GridView2.Rows[GridView2.SelectedIndex].Cells[5].Text;
        mysql.Text = GridView2.Rows[GridView2.SelectedIndex].Cells[6].Text;

    }

那就是我在事件部分所做的,因为我确信它将是网格视图内的一行,所以if (GridView2.SelectedIndex == 0)

谢谢你 :)

于 2010-12-23T03:15:09.697 回答