English 中文(简体)
ASP. NET:如何从GridView控制中从一排获得价值
原标题:ASP.NET: How to get values from a selected row from GridView control

我增加了对我的协会的GridView控制。 网页净额和数据附在<代码>后 清单和编号; 清单中包含一个简单的习俗物体,其定义是:

public class PersonRecord
{
    public int PersonId { get; set; }
    public string Name { get; set; }
    public string Title { get; set; }
    public string Description { get; set; }
    public string Notes { get; set; }
}

我已定下<代码>AutoGenerateSelectButton,并附上了<代码>的活动笔记。 选定IndexChanged 活动。 我可以看到我的手势大火,我可以通过使用MyGridView.S selectedIndex获得选定的浏览指数。

www.un.org/Depts/DGACM/index_spanish.htm 我的问题是: 我如何利用选定的行程指数来为选定的记录取得个人成绩?

我想MyGridView.Rows[MyGridView.S selectedIndex].Cells[0],但这样做是因为MyGridView.Rows.Count0。

TIA

最佳回答

您在服务器上是如何储存从GridView中获取的数据的? 由于你有选定浏览指数,你才需要再次获得数据来源。 如果您在会议上坚持下去,那么你就能够仅仅获得该届会议的反对,并在选定的用户指数中找到目标。

问题回答

仅仅因为我没有同时发挥网络应用的作用,我决定看看这是否我可以做些什么。 Alas,无用。 这对我来说是罚款的:

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!Page.IsPostBack)
        {
            var persons = CreatePersons();
            GridView1.DataSource = persons;
            GridView1.DataBind();
        }
    }

    private List<PersonRecord> CreatePersons()
    {
        var person = new PersonRecord
                         {
                             PersonId = 1,
                             Name = "greg",
                             Title = "Supreme Coder",
                             Description = "Nada",
                             Notes = "foo bar"
                         };

        var person2 = new PersonRecord
        {
            PersonId = 2,
            Name = "Sam",
            Title = "Junior Coder",
            Description = "Nada",
            Notes = "foo bar"
        };

        var list = new List<PersonRecord> {person, person2};

        return list;
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        var row = GridView1.Rows[0];
        var cell = row.Cells[1];
        var value = cell.Text;


    }

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        int index = GridView1.SelectedIndex;
        var row = GridView1.Rows[index];
        var nameCell = row.Cells[2];
        var name = nameCell.Text;

        Label1.Text = name;
    }
}

你最有可能失败,因为你正在选择选定一栏(阁下),但我认为,你应该从这个囚室中找到一些东西(与它一起玩).)。 这也可能是具有约束力的不良模式。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签