GridView Row indes相关 [英] GridView Row indes Related

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

问题描述

全部交易



我有多个记录的gridview。



gridview有两列。



第一列有下拉列表,第二列有按钮。



我想要显示所选项目的详细信息onclick of该特定行的按钮。



我能够显示第一行下拉项目的详细信息,但不能显示其他行下拉项目。



基本上问题在于所选行的行索引。





任何建议。



提前感谢你。

解决方案

推荐此链接



如何获取链接按钮上所选行的gridview值按钮 [ ^ ]



问候。 。:)






试试这个。



//你的gridview命令事件

 受保护  void  yourgrid_RowCommand( object  sender,GridViewCommandEventArgs e)
{
GridViewRow row =(GridViewRow) (((按钮)e.CommandSource).NamingContainer);
DropDownList ddl =(DropDownList)row.FindControl(' yourdropdownid');
// 现在选择值
string value = ddl.SelectedValue;
}





希望它有所帮助。


> Guys终于得到了解决方案。 ..........



感谢Harshit Rawal。



说明:



GridView行的RowIndex包含在CommandArgument属性中。因此,使用该索引,您可以获得GridView Row的引用。



我的Griedview就像这样..



 <   asp:GridView     ID   =  GridView1     runat   =  server    AutoGenerateColumns   =  false    OnRowCommand   =  OnRowCommand >  <   >  <   asp:ButtonField     CommandName   = 查看    ButtonType   = 按钮    /  >  <   asp:TemplateField  >  <   ItemTemplate  >  <   asp:DropDownList     ID   =  ddlitem    runat   =  server >  <   / asp:DropDownList  >  <   / ItemTemplate  >  <   / asp:TemplateField  >  <   /列 >  
< / asp:GridView >

我想要的是我处理我的gridview的OnRowCommand





 受保护的  Sub  OnRowCommand( ByVal  sender < span class =code-keyword> As   Object  ByVal  e  As  GridViewCommandEventArgs)

如果 e.CommandName = 查看 然后
Dim i 正如 整数 = Convert.ToInt32(e.CommandArgument)
Dim ddl < span class =code-keyword> As DropDownList = DirectCast (GridView1.Rows(i).FindControl( ddlitem),DropDownList)
Dim x As String = ddl.SelectedValue

End 如果


结束 Sub


Deal All

I have gridview with multiple record.

gridview has two column.

First column has dropdown & second column has button.

I want show detail of selected item onclick of button of that particular row.

I can able to show the detail of first row dropdown item but not the other row dropdown item.

Basically problem is in row index of selected row.


Any suggestion.

Thanking you in advance.

解决方案

Refer this link

How to get the gridview values for the selected row on link button click[^]

Regards..:)


Hi,

try this.

// your gridview command event

protected void yourgrid_RowCommand(object sender, GridViewCommandEventArgs e)
{
    GridViewRow row = (GridViewRow)(((Button)e.CommandSource).NamingContainer);
    DropDownList ddl = (DropDownList)row.FindControl('yourdropdownid');
    // now select value
    string value = ddl.SelectedValue;
}



hope it helps.


>Guys Finally got Solution...........

Thanks to Harshit Rawal also.

Explanation:

The RowIndex of the GridView Row is contained in the CommandArgument Property. Thus with that index you can get the reference of the GridView Row.

My Griedview is like this ..

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnRowCommand="OnRowCommand">                                                                               <Columns>                                                                                    <asp:ButtonField CommandName="View" ButtonType="Button" />                                                                                    <asp:TemplateField>                                                                                        <ItemTemplate>                                                                                            <asp:DropDownList ID="ddlitem" runat="server">                                                                                            </asp:DropDownList>                                                                                        </ItemTemplate>                                                                                    </asp:TemplateField>                                                                         </Columns>
</asp:GridView>

What i want i got it on handling OnRowCommand of my gridview



Protected Sub OnRowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)

If e.CommandName = "View" Then
            Dim i As Integer = Convert.ToInt32(e.CommandArgument)
            Dim ddl As DropDownList = DirectCast(GridView1.Rows(i).FindControl("ddlitem"), DropDownList)
            Dim x As String = ddl.SelectedValue

        End If


End Sub


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

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