简体   繁体   English

在Button1_Click上,需要从选定的DataKey中获取值(用户在gridview中按Select并突出显示行)

[英]On Button1_Click need to get value from selected DataKey (User presses Select in gridview and highlights row)

This is kiling me. 这让我很生气。 On Button1_Click I need to get the value from selected DataKey (User presses Select in gridview and highlights row)..Can anyone help? 在Button1_Click上,我需要从选定的DataKey中获取值(用户在gridview中按Select,然后突出显示行)。有人可以帮忙吗? Thank You.. 谢谢..

    protected void Button1_Click(object sender, EventArgs e)
   {      
    string id = GridView1.SelectedDataKey.Value.ToString(); 
    Label1.Text = id;
   }

You haven't mentioned what's not working, do you get any errors? 您没有提到什么不起作用,您是否遇到任何错误?

To retrieve the SelectedDataKey you have to tell the GridView what's the primary key column of your datasource via it's property DataKeyNames . 要检索SelectedDataKey,您必须通过其属性DataKeyNames告诉GridView数据源的主键列是什么。 You could also use the GridView's SelectedValue property. 您也可以使用GridView的SelectedValue属性。

If all does not work, you should provide source code. 如果所有方法均无效,则应提供源代码。 Maybe you are binding the GridView on every postback. 也许您在每个回发上都绑定了GridView。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM