开发者

template field visible only in insert mode

开发者 https://www.devze.com 2023-01-23 03:58 出处:网络
Is it possibile to have templateField开发者_JAVA技巧 from detailsView visible only in inserMode?

Is it possibile to have templateField开发者_JAVA技巧 from detailsView visible only in inserMode?

<asp:TemplateField  HeaderText="My Header" SortExpression="TypeName" Visible='<%# Eval("DetailsView1.CurrentMode == DetailsViewMode.Insert")%>'>

this doesnt work exception is:

Databinding expressions are only supported on objects that have a DataBinding event. System.Web.UI.WebControls.TemplateField does not have a DataBinding event.

Thanks for help


I know this is an old question, but I just hate it whenever I see someone giving an answer that has absolutely nothing to do with the question being asked.

The answer to THE question is: YES.

And the way to accomplish it is as follows:

In the DetailsView control, define an OnModeChanged event.

In the OnModeChanged event handler, type the following, replacing ### with the index into the DetailsView of the row you want to be visible only when in insert mode:

    DetailsView dv = sender as DetailsView;
    TableRow tr = dv.Rows[###] as TableRow;
    DataControlFieldCell dcfc = tr.Controls[0] as DataControlFieldCell;
    dcfc.ContainingField.Visible = dv.CurrentMode == DetailsViewMode.Insert;


When you convert a field to a template field, you should get separate templates for each mode (and you can edit each one):

    <asp:TemplateField HeaderText="CustomerName" SortExpression="CustomerName">
    <EditItemTemplate>
        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("CustomerName") %>'></asp:TextBox>
    </EditItemTemplate>
    <InsertItemTemplate>
        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("CustomerName") %>'></asp:TextBox>
    </InsertItemTemplate>
    <ItemTemplate>
        <asp:Label ID="Label1" runat="server" Text='<%# Bind("CustomerName") %>'></asp:Label>
    </ItemTemplate>
</asp:TemplateField>
0

精彩评论

暂无评论...
验证码 换一张
取 消