C# listview持久插入值
“我有一个列表视图,其中包含要编辑的项目和一个插入项 插入项模板有几个文本框,但是我想将其中一个文本框设置为只读,并在其中保留一个值,该值将在每次插入后保持不变C# listview持久插入值,c#,asp.net,listview,C#,Asp.net,Listview,“我有一个列表视图,其中包含要编辑的项目和一个插入项 插入项模板有几个文本框,但是我想将其中一个文本框设置为只读,并在其中保留一个值,该值将在每次插入后保持不变 <InsertItemTemplate> <tr style=""> <td> <asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" /> <asp:Button
<InsertItemTemplate>
<tr style="">
<td>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" />
</td>
<td>
<asp:TextBox ID="tc_dateTextBox" runat="server" Text='<%# Bind("tc_date") %>' />
</td>
<td>
<asp:TextBox ID="tc_costTextBox" runat="server" Text='<%# Bind("tc_cost") %>' />
</td>
<td>
<asp:TextBox ID="tc_typeTextBox" runat="server" Text='<%# Bind("tc_type") %>' />
</td>
<td>
<asp:TextBox ID="tc_commentTextBox" runat="server" Text='<%# Bind("tc_comment") %>' />
</td>
<td> </td>
<td>
<asp:TextBox ID="tc_t_idTextBox" runat="server" Text='<%# Bind("tc_t_id") %>' Width="15" ReadOnly="true" />
</td>
</tr>
</InsertItemTemplate>
tc_t_idTextBox是我设置为只读的文本框,希望它在每次插入时都保持相同的值。要使文本框为只读,您需要设置readonly=true
<InsertItemTemplate>
<tr style="">
<td>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" />
</td>
<td>
<asp:TextBox ID="tc_dateTextBox" runat="server" Text='<%# Bind("tc_date") %>' />
</td>
<td>
<asp:TextBox ID="tc_costTextBox" runat="server" Text='<%# Bind("tc_cost") %>' />
</td>
<td>
<asp:TextBox ID="tc_typeTextBox" runat="server" Text='<%# Bind("tc_type") %>' />
</td>
<td>
<asp:TextBox ID="tc_commentTextBox" runat="server" Text='<%# Bind("tc_comment") %>' />
</td>
<td> </td>
<td>
<asp:TextBox ID="tc_t_idTextBox" runat="server" Text='<%# Bind("tc_t_id") %>' Width="15" ReadOnly="true" />
</td>
</tr>
</InsertItemTemplate>
例如:
<asp:TextBox ReadOnly="True"...
我终于找到了解决问题的方法。
我的工作是在页面中添加一个隐藏字段
<asp:HiddenField ID="h_tc_t_id_holder" Value="0" runat="server" />
在列表视图中,我添加了
OnPreRender="ListView1_OnPreRender"
暗藏
protected void ListView1_OnPreRender(object sender, EventArgs e)
{
ListView1.DataBind();
((TextBox)ListView1.InsertItem.FindControl("tc_t_idTextBox")).Text = h_tc_t_id_holder.Value;
}
他已经这么做了,但老实说,我不明白他面临的问题是什么:/