我正在尝试通过由两个文本框控件和一个链接控件组成的空数据模板控件将数据插入到 xml 文件中:
...该设计:
<emptydatatemplate>
No Data Found. <br />
<asp:TextBox ID="txtAltprodID" runat="server"></asp:TextBox><br />
<asp:TextBox ID="txtAltprodNum" runat="server"></asp:TextBox><br />
<asp:LinkButton ID="lnkpro" runat="server" OnClick="writeProductInfo" Text="Add Product Number"></asp:LinkButton>
</emptydatatemplate>
文本框控件提交的输入将放置在以下 XML 文件的产品表中:
<PersonalData>
<products>
<product>
<productID>2</productID>
<productNumber>123744</productNumber>
</product>
<product>
<productID>7</productID>
<productNumber>123456</productNumber>
</product>
</products>
<customers>
<customer>
<LastName>Doe</LastName>
<FirstName>Sam</FirstName>
<Address>1234 Crescent RD</Address>
<City>San Antonio</City>
<State>Texas</State>
<ZipCode>67894</ZipCode>
</customer>
</customers>
</PersonalData>
我为添加产品信息链接创建了以下事件处理程序:
Public Sub writeProductInfo(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim altprodID As String = DirectCast(gvProductNumber.EmptyDataTemplate.FindControl("txtAltprodID"), TextBox).Text
Dim altprodNum As String = DirectCast(gvProductNumber.EmptyDataTemplate.FindControl("txtAltprodNum"), TextBox).Text
BindGridView()
Dim oDs As DataSet = gvProductNumber.DataSource
Dim oDr As DataRow = oDs.Tables(0).NewRow
oDr("productID") = altprodID
oDr("productNumber") = altprodNum
oDs.Tables(0).Rows.Add(oDr)
oDs.WriteXml(Request.PhysicalApplicationPath + "~/xml/PersonDataVI.xml")
BindGridView()
End Sub
...但是,我的语法存在问题:
Dim altprodID As String = DirectCast(gvProductNumber.EmptyDataTemplate.FindControl("txtAltprodID"), TextBox).Text
Dim altprodNum As String = DirectCast(gvProductNumber.EmptyDataTemplate.FindControl("txtAltprodNum"), TextBox).Text
...我可以在如何设置上面的两行以从空数据模板中读取文本框控件的 ID 方面获得一些帮助吗?谢谢你