我有以下gridview。
<asp:GridView ID="gvMarks" runat="server" AutoGenerateColumns="false"
DataKeyNames="MarkId" Width="80%" onrowdatabound="gvMarks_RowDataBound"
ShowFooter="True" onrowcommand="gvMarks_RowCommand">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
SubjectCode
</HeaderTemplate>
<FooterTemplate>
<asp:DropDownList ID="dlSubjectCode" runat="server" width="100px" AutoPostBack="false"></asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Mark
</HeaderTemplate>
<FooterTemplate>
<asp:TextBox ID="txtInternalMark" runat="server" ></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Insert
</HeaderTemplate>
<FooterTemplate>
<asp:LinkButton ID="lnkInsert" runat="server" Text="Insert"
CommandName="Insert" ></asp:LinkButton>
</FooterTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="White" ForeColor="#000066" />
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
</asp:GridView>
如果我在txtInternalMark中输入一些值,我不会在后面的代码中设置它的值。我将值设为“”。使用以下代码
if (e.CommandName.Equals("Insert"))
{
TextBox txtInternalMark = (TextBox)gvMarks.FooterRow.FindControl("txtInternalMark");
lblMessage.Text = txtInternalMark .Text;
}
任何人都可以帮助在代码隐藏中获取textbox的值。
答案 0 :(得分:0)
海
string Ingredient = ((TextBox) gvMarks.FooterRow.FindControl("txtInternalMark")).Text;
Response.Write(Ingredient);
如果不起作用,请将CausesValidation="False"
添加到ur linkbutton lnkInsert