单击Gridview中的“选择按钮”时查看详细信息(所有字段)

时间:2015-07-08 13:11:14

标签: javascript c# asp.net visual-studio-2010 gridview

在webform asp页面中单击Gridview中的“选择”按钮时,如何获取新asp页面中所有字段的视图。我想我必须创建一个将在“OnClientClick”上调用的函数。这是我的代码。我怎么能执行这个任务?非常感谢你,最好的问候

 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
    DataKeyNames="ID" DataSourceID="ObjectDataSource1" AllowPaging="True" 
    AllowSorting="True">
    <Columns>
        <asp:TemplateField ShowHeader="False">
            <EditItemTemplate>
                <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" 
                    CommandName="Update" Text="Update"></asp:LinkButton>
                &nbsp;<asp:LinkButton ID="CancelButton" runat="server" CausesValidation="False" 
                    CommandName="Cancel" Text="Cancel"></asp:LinkButton>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" 
                    CommandName="Edit" Text="Edit"></asp:LinkButton>


                &nbsp;<asp:LinkButton ID="SelectButton" runat="server" OnClientClick="" CausesValidation="False" 
                    CommandName="Select" Text="Select"></asp:LinkButton>



                &nbsp;<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" 
                    CommandName="Delete" Text="Delete"></asp:LinkButton>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

1 个答案:

答案 0 :(得分:0)

对于按钮点击事件,请尝试:

<asp:gridview id="NewGridView" 
    datasourceid="NewSqlDataSource" 
    autogeneratecolumns="false"
    onrowcommand="NewGridView_RowCommand"
    runat="server">

    <columns>
      <asp:buttonfield buttontype="Button" 
        commandname="Select"
        headertext="Select People" 
        text="Select"/>
    </columns>
</asp:gridview>


void NewGridView_RowCommand(Object sender, GridViewCommandEventArgs e)
{

if(e.CommandName=="Select")
{      
  int index = Convert.ToInt32(e.CommandArgument);  

  GridViewRow selectedRow = NewGridView.Rows[index];
}
}

或检查链接,

https://msdn.microsoft.com/en-us/library/bb907626.aspx