2012-08-28 59 views
0

「我有一個項目一個ListView編輯和插入。然而列表視圖持久插入值

插入項模板有幾個文本框,我想使文本框的一個只讀,並且在保持它的值每次插入後會持續。

<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> &nbsp;</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是我只讀做出的一個,想那是,保持在每個插入相同的值框。

回答

0

我終於想通了如何解決我的問題。 我的工作是爲頁面添加一個隱藏字段。

<asp:HiddenField ID="h_tc_t_id_holder" Value="0" runat="server" /> 

在代碼後面我將該值設置爲隱藏字段。

h_tc_t_id_holder.Value = App_id; 

在列表視圖中我添加

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; 
} 
1

爲了使一個TextBox只讀你將需要設置ReadOnly = true

例如:

<asp:TextBox ReadOnly="True"... 
+0

他已經在這樣做,但說實話,我不明白什麼是他所面臨的問題:/ – Icarus