GridView选择的项目 [英] GridView selected Items

查看:61
本文介绍了GridView选择的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要让ListBox选择项目,我这样写.我使用GridView而不是ListBox来类似.如何编写相同的代码.在Girdview中,我有一些行我想读取其中的一些并将其存储为字符串数据类型.

To get the ListBox selected Items, i wrote like this . simillarly instead of ListBox i''m using GridView.How to write the same code.In Girdview i have some rows i want to read some of them and store it into a string datatype.

ListBox LstBox = (dgi.FindControl("lstType") as ListBox);
string strselect = "";
for (int j = 0; j < LstBox.Items.Count; j++)
{
     ListItem li = LstBox.Items[j];
     if (li.Selected)
     {
        strselect = strselect + ", " + li.Value;
     }
}

推荐答案

foreach (DataGridViewRow row in gdv.Rows)
{
string col1Val = row.Cells[0].Value.ToString();
string col2Val =  row.Cells[1].Value.ToString();
}


您好!

您可以使用模板字段并向其中添加一个命名命令,然后可以检查在RowCommand事件中单击了哪些模板字段(并且您还可以获取行索引),请参见下文.

在.aspx页中:

Hello !

you can use template fields and add a named command to it then you can check which of them was clicked in the RowCommand event (and u can also get the row index as well) see below.

in .aspx page:

<asp:TemplateField ShowHeader="False">
            <ItemTemplate>
                <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="false"

                    CommandName="MyCommand" Text="Button" CommandArgument='<%# Container.DataItemIndex %>'></asp:LinkButton>
            </ItemTemplate>
        </asp:TemplateField>



在RowCommand事件的.aspx.cs页中:



in .aspx.cs page on RowCommand Event:

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
            {
                if(e.CommandName.Equals("MyCommand"))
                {
                    int row = Int32.Parse(e.CommandArgument.ToString());


                }


            }



谢谢.



Thanks.


这篇关于GridView选择的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆