本文介绍了而不使用SelectedIndexChanged,从gridview检索每一行的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个gridview
在不使用SelectedIndexChanged的情况下,当单击每一行中的每个按钮时,如何从gridview中检索每一行的值?

这是我的aspx代码

i have a gridview
without using SelectedIndexChanged, how can i retrieve the value of each row from gridview when click on each button in each row?

this is my aspx code

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
                DataKeyNames="ProductID" DataSourceID="SqlDataSource1"
                ShowHeader="False" AllowPaging="True" BorderColor="White" CellPadding="6"
                GridLines="None" Height="100px" Width="800px">
<Columns>

<asp:TemplateField>
 <ItemTemplate>
 Card Name:
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
 <br />
Cost :
  <asp:Label ID="Label2" runat="server" Text='<%# Bind("Price") %>'></asp:Label>
<br />
<asp:Label ID="Label3" runat="server" Text='<%# Bind("ProductImgID") %>' ></asp:Label>
 <asp:Image ID="Image3" runat="server" ImageUrl='<%# Eval("ProductImgUrl", "images/{0}") %>'  />

                            <br />
<asp:Button ID="btnAddProduct" runat="server" Text="Add" />
                            <br />

                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>

推荐答案

    //get the reference for the button
    Button btn = (Button)sender;
    //Get reference of the gridview row of the button clicked.
    GridViewRow gvReference = (GridViewRow)(btn.Parent.Parent);

    // Get the text of the label
String strLabel1  = ((Label)gvReference.FindControl("Label1")).Text.ToUpper();
 ...
 ...





在btnAddProduct单击上调用javascript函数以获取值.
希望这会有所帮助.



or

Call a javascript function on the btnAddProduct click to get the values.
Hope this helps.


这篇关于而不使用SelectedIndexChanged,从gridview检索每一行的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 02:09