我按了gridview,在单击按钮后,我需要从templatefield“ VyskaStavky”的文本框中获取值。请有人能告诉我我该怎么做吗?我尝试了类似CommandArgument ='<%#Eval(“ Id”)+“,” + Eval(“ VyskaStavky”)%>'的操作,但是我遇到了问题,因为VyskaStavky不是类Kurz的属性(我对datasourceID的命名是类别名称+来自数据的D和来自源的S)
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataSourceID="KurzDS" DataKeyNames="Id" OnRowCommand="GridView1_RowCommand">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" SortExpression="Id" ReadOnly="True" Visible="False" />
<asp:BoundField DataField="Zapas" HeaderText="Zapas" SortExpression="Zapas" ReadOnly="True" Visible="False" />
<asp:BoundField DataField="AktKurz" HeaderText="AktKurz" SortExpression="AktKurz" />
<asp:BoundField DataField="Tip" HeaderText="Tip" SortExpression="Tip" />
<asp:BoundField DataField="Handicap" HeaderText="Handicap" SortExpression="Handicap" />
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="VyskaStavky" runat="server" Text=""></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="Button1" Text='Podat stavku' CommandArgument='<%# Eval("Id")%>' CommandName="PodatStavku" runat="server" CausesValidation="false" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
非常感谢
我解决了我的问题。我更改了模板按钮(从命令更改为onclick)
<ItemTemplate>
<asp:Button ID="Button1" Text='Podat stavku' OnClick="Button1_Click" runat="server" CausesValidation="false" />
</ItemTemplate>
在C#中我得到了价值
protected void Button1_Click(object sender, EventArgs e)
{
Button btn = sender as Button;
GridViewRow row = btn.NamingContainer as GridViewRow;
string pk = GridView2.DataKeys[row.RowIndex].Values["Id"].ToString();
TextBox ss = GridView2.Rows[row.RowIndex].Cells[3].FindControl("VyskaStavky") as TextBox;
//ss.text have my requested value
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句