而不使用SelectedIndexChanged,从gridview检索每一行的值? [英] without using SelectedIndexChanged, retrieve value of each row from gridview?

查看:71
本文介绍了而不使用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>

推荐答案



为btnAddProduct编写按钮单击事件.在按钮中,单击以编写以下代码,

Hi,

write a button click event for the btnAddProduct. In the button click write the below code,

    //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检索每一行的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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