【发布时间】:2021-09-09 09:01:27
【问题描述】:
我有一个 gridview 和一个按钮。当我单击按钮时,我的表单中会写一个句子。我想调用在 gridview 中输入的数据并在标签中查看它们。 这是我的代码,但它不起作用:
//code of gridview:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px"
CellPadding="4" DataKeyNames="ProductID" DataSourceID="SqlDataSource2"
CssClass="grid">
<Columns>
<asp:ImageField DataImageUrlField="ImageUrl" HeaderText="image">
<ControlStyle Height="130px" Width="130px" />
</asp:ImageField>
<asp:BoundField DataField="Description" HeaderText="department"
SortExpression="Description" />
<asp:BoundField DataField="ProductName" HeaderText="name"
SortExpression="ProductName" />
<asp:BoundField DataField="ProductID" HeaderText="code"
SortExpression="ProductID" ReadOnly="True" />
</Columns>
<FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
<HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
<PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
<RowStyle BackColor="White" ForeColor="#003399" />
<SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<SortedAscendingCellStyle BackColor="#EDF6F6" />
<SortedAscendingHeaderStyle BackColor="#0D4AC4" />
<SortedDescendingCellStyle BackColor="#D6DFDF" />
<SortedDescendingHeaderStyle BackColor="#002876" />
</asp:GridView>
//the code of button
protected void Button1_Click(object sender, EventArgs e)
{
if (RadioButton2.Checked)
txtid.Text = "name"+ProductName+"department"+description+"code"+productID;
}
【问题讨论】:
-
您希望此按钮从网格中的哪一行获取数据?是否选择了当前行?
-
我的网格视图中只有一行
标签: c# asp.net gridview webforms