将数据从网格视图单元格检索到文本框

发布于 2024-10-08 22:53:14 字数 619 浏览 3 评论 0原文

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

我已经启用自动回发到文本框的

新值,如下所示 但是,我的代码

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 开发人员

I am trying to retrieve a cell data to a textbox , that will happen when i select any row in the grid view , the textbox will take the new value

I already enabled auto post back to the textbox

here is my code

protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
{

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

however , there is not error in the syntax , it doesn't retrieve any thing in the textbox , any suggestions ?

i am using

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;

I work in C# , Visual studio 2010 express web developer

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浮世清欢 2024-10-15 22:53:14

根据 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 + ".";

From VS 2010 documentation, I would recommend checking if the row and Cells are not null first.

// 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 + ".";
[浮城] 2024-10-15 22:53:14
 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)

谢谢:)

 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;

    }

that what i did in the event section, because i am sure it will be one row inside the grid view , so if (GridView2.SelectedIndex == 0)

thank you :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文