我正在使用asp.net和C#创建Web模板。
在我的用户控制页面中,我必须在列表视图中动态创建表。我只是从XML文件中读取数据,然后检索每个表的名称和列数和行数。当我创建表时,我为每个单元格分配名称和ID。在此动态表中,一旦用户单击每行的编辑按钮,该行的所有单元格将更改为textbox
。然后用户可以更改此textboxes
的数据,
但在我的更新功能中,我无法通过textboxes
访问这些id
并将数据存储在数据库中。
下面是我在ItemDataBound
函数创建的动态表代码:
System.Data.DataRowView rowView = e.Item.DataItem as System.Data.DataRowView;
TableRow tr_DataBound = new TableRow();
TableCell tc_DataBound = new TableCell();
for (int i = 1; i <= pkCounter + nonPkCounter; i++)
{
//tc_DataBound = new TableCell();
tc_DataBound = new TableCell();
TextBox tb = new TextBox();
//(TextBox)e.Item.FindControl("td_EditTemp" + i);
tb.Width = 110;
tb.Text = rowView[i - 1].ToString();
tb.ID = "td_EditTemp" + i;
tc_DataBound.Controls.Add(tb);
tc_DataBound.CssClass = "th_ItemTemplate";
tr_DataBound.Cells.Add(tc_DataBound);
}
tr_DataBound.Cells.Add(tc_DataBound);
Table table_Lv_ItemTemplate = (Table)e.Item.FindControl("Table_Lv_ItemTemplate");
table_Lv_ItemTemplate.Rows.Add(tr_DataBound);
我的listview
代码是:
<asp:ListView ID="lv_Uc_Module" runat="server"
onitemediting="lv_Uc_Module_ItemEditing"
onitemcanceling="lv_Uc_Module_ItemCanceling"
onitemdeleting="lv_Uc_Module_ItemDeleting"
OnItemDataBound="lv_Uc_Module_ItemDataBound"
OnSorting="lv_Uc_Module_Sorting">
<LayoutTemplate>
<asp:Table runat="server" ID="table_Lv_Layout">
<asp:TableRow runat="server" ID="tr_Table_Layout">
<asp:TableCell runat="server" ID="td_Table_Layout">
<asp:Table runat="server" ID="itemPlaceholderContainer">
<asp:TableRow runat="server" ID="tr_Table_IphContainer">
<asp:TableHeaderCell runat="server">
<asp:PlaceHolder ID="th_Ph_Lv_header" runat="server"></asp:PlaceHolder>
</asp:TableHeaderCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">
<asp:PlaceHolder runat="server" ID="itemPlaceholder" />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server" ID="tr_Validate_Table_Layout">
<asp:TableCell runat="server" ID="td_Validate_Table_Layout" HorizontalAlign="Center" BackColor="#CCCCCC">
<asp:ValidationSummary ID="ValidationSummary1" runat="server" HeaderText="You received the following errors:" ShowMessageBox="true" ShowSummary="false" ValidationGroup="VGEditTmp" />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
<br />
<asp:DataPager ID="lv_DataPager" runat="server" PagedControlID="lv_Uc_Module" PageSize="25" OnPreRender="lv_DataPager_PreRender">
<Fields>
<asp:NextPreviousPagerField ButtonType="Image" ShowFirstPageButton="true" ShowLastPageButton="true" FirstPageImageUrl="~/Images/First.png" LastPageImageUrl="~/Images/Last.png" NextPageImageUrl="~/Images/Next.png" PreviousPageImageUrl="~/Images/Previous.png" />
<asp:TemplatePagerField>
<PagerTemplate>
<span style="color:Blue;">
</span>
</PagerTemplate>
</asp:TemplatePagerField>
</Fields>
</asp:DataPager>
</LayoutTemplate>
<ItemTemplate>
<asp:TableRow runat="server">
<asp:TableCell runat="server">
<asp:Table runat="server" ID="Table_Lv_ItemTemplate"></asp:Table>
</asp:TableCell>
<asp:TableCell runat="server">
<asp:Button ID="btn_Edit" runat="server" CommandName="Edit" Text="" CssClass="btn_Edit" CausesValidation="True" Visible="false" />
<asp:Button ID="btn_Delete" runat="server" CommandName="Delete" Text="" CssClass="btn_Delete" CausesValidation="false" OnClientClick="return confirm('Are you sure you want to delete this item?');" Visible="false" />
</asp:TableCell>
</asp:TableRow>
</ItemTemplate>
</asp:ListView>
我在后台代码的更新功能中使用以下方法来访问textbox
处更改的数据:
TextBox tb = (lv_Uc_Module.Items[e].FindControl("td_EditTemp" + i + "_" + e)) as TextBox;
您能否指导我如何访问这些textboxes
数据。
感谢您的考虑。
答案 0 :(得分:0)