我试图提取嵌入在gridview中的模板字段文本框中填充的值。我尝试过几种不同的方式,但不断收到错误消息。我能够从嵌入在同一gridview中的templatefield下拉控件中提取值。
标记:
<asp:TemplateField HeaderText="Renewal Date" >
<ItemTemplate>
<ajaxToolkit:CalendarExtender ID="cexRenewalDate" runat="server" TargetControlID="txtRenewalDate" PopupPosition="TopRight"
Format="MM/dd/yyyy" PopupButtonID="btnimgCalendar" />
<asp:TextBox ID="txtRenewalDate" runat="server" CssClass="RenewalDateTextBoxStyle"
onKeyPress="javascript: return false;" onPaste="javascript: return false;"/>
<asp:ImageButton ID="btnimgCalendar" runat="server" ImageUrl="~/Images/Calendar.png" CssClass="CalendarImageButtonStyle"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Action">
<ItemTemplate>
<asp:DropDownList ID="drpOFActions" runat="server" CssClass="ActionDropDownStyle"/>
<asp:LinkButton ID="lnkOFCommit" runat="server" Text=" Commit " OnClick="lnkCommitOF_Click" CssClass="CommitLinkButtonStyle"
OnClientClick="return confirm('Are you sure you want to complete this action?');"
CommandArgument='<%# Container.DataItemIndex %>' />
</ItemTemplate>
</asp:TemplateField>
代码背后:
Dim temp As String = CType(grdGeneratedOrderForms.Rows(rowIndex).FindControl("txtRenewalDate"), TextBox)
这会抛出一个System.Web.UI.Control&#39;无法转换为&#39; System.Windows.Forms.TextBox&#39;错误。
我也试过在别人的建议中使用它:
Dim temp As String = TryCast(grdGeneratedOrderForms.Rows(rowIndex).FindControl("txtRenewalDate"), System.Web.UI.Control.TextBox)
这会抛出一个Type&#39; System.Web.UI.Control.TextBox&#39;没有定义错误。
但是,当我使用下面的内容来拉取我的下拉控件的值时,我没有问题:
Dim Action As Integer = TryCast(grdGeneratedOrderForms.Rows(rowIndex).FindControl("drpOFActions"), DropDownList).SelectedValue
以下是我的命名空间声明:
Imports Oracle.DataAccess.Client
Imports System.IO
Imports System.Windows.Forms
Imports Aspose.Words
Imports Aspose.Words.Tables
Imports Ionic.Zip
非常感谢任何想法......谢谢!
答案 0 :(得分:1)
试试这个。我认为你的using语句中存在名称空间冲突
Dim temp As String = CType(grdGeneratedOrderForms.Rows(rowIndex).FindControl("txtRenewalDate"), System.Web.UI.WebControls.TextBox).Text