Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
333 views
in Technique[技术] by (71.8m points)

vb.net - retrieve data from gridview row to an asp.net form

I would like to retrieve a row from the gridview by clicking on ImageButton (Booking): here is the code of my grid view:

    <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>

The textbox of the form.aspx page that should be filed from the gridview row:

<asp:TextBox ID="trade" runat="server" CssClass="input , focus"></asp:TextBox>
<asp:TextBox ID="carrier" runat="server" CssClass="input , focus"></asp:TextBox>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Add GridView RowCommand event and command argument for image button where you can pass an id or something to determine the current row.

  <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

You can refer msdn for more : http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowcommand.aspx


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...