0

我想通过单击 ImageButton(预订)从网格视图中检索一行:这是我的网格视图的代码:

    <asp:GridView ID="GridView1" runat="server" Height="150px" Width="284px" 
                         CssClass="tb" AutoGenerateColumns="False" DataSourceID="SqlDataSource1">

                         <Columns>
                          <asp:TemplateField HeaderText=" Booking">
                         <ItemTemplate>
                              <asp:ImageButton ID="booking" runat="server"   HeaderText="Booking" ImageUrl="booking_icon.ico" PostBackUrl="form.aspx"/>
                         </ItemTemplate>
                         </asp:TemplateField>

                            <asp:BoundField DataField="Trade" HeaderText="Trade" SortExpression="Trade" />
                             <asp:BoundField DataField="CARRIER" HeaderText="CARRIER" 
                                 SortExpression="CARRIER" />
                            </Columns>
 </asp:GridView>

应从 gridview 行归档的 form.aspx 页面的文本框:

<asp:TextBox ID="trade" runat="server" CssClass="input , focus"></asp:TextBox>
<asp:TextBox ID="carrier" runat="server" CssClass="input , focus"></asp:TextBox>
4

1 回答 1

0

为图像按钮添加 GridView RowCommand 事件和命令参数,您可以在其中传递 id 或其他内容来确定当前行。

  <asp:GridView  onrowcommand="gvRowCommand" ID="GridView1" runat="server" Height="150px" Width="284px" 
                     CssClass="tb" AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
 <ItemTemplate>
    <asp:ImageButton  CommandArgument='<%# Eval("SomeId") %>' ID="booking" runat="server"   HeaderText="Booking" ImageUrl="booking_icon.ico" />
</ItemTemplate>

C#

   protected void gvRowCommand(object sender, GridViewCommandEventArgs e)
   {
      var someId = e.CommandArgument;
   }

VB.Net

 Protected Sub gvRowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gv.RowCommand

   Dim someId As Integer = Convert.ToInt32(e.CommandArgument)

End Sub

您可以参考 msdn 了解更多信息:http: //msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowcommand.aspx

于 2013-06-26T04:02:39.067 回答