سؤال

i'm trying to build a gridview and detail to manage user notes .

everything work fine but I need to add a textbox with multiline inside the detail view :

    <asp:DetailsView ID="DetailsView1" ClientIDMode="Static" runat="server" SkinID="detailview" AllowPaging="True" Width="700px" AutoGenerateRows="False" DataKeyNames="id,Expr1" DataSourceID="SqlDataSource2" HeaderText="الملاحظات" oniteminserted="updategridview" onitemupdated="updategridview">
            <Fields>
                <asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" ReadOnly="True" SortExpression="id" />
                <asp:BoundField DataField="user_id" HeaderText="user_id" SortExpression="user_id" />
                <asp:BoundField DataField="xdate" HeaderText="xdate" SortExpression="xdate" />
                <asp:TemplateField HeaderText="xcontent">
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Eval("xcontent") %>'></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="update" ClientIDMode="Static" TextMode="MultiLine" Text='<%# Eval("xcontent") %>' Height="100px" runat="server"></asp:TextBox>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:TextBox ID="insert" ClientIDMode="Static" TextMode="MultiLine" Text="" Height="100px" runat="server"></asp:TextBox>
                    </InsertItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="name" HeaderText="name" SortExpression="name"  />
                <asp:CommandField ShowInsertButton="True" />
                <asp:CommandField ShowEditButton="True"/>
            </Fields>
        </asp:DetailsView>


   <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:samy_sarc %>" InsertCommand="INSERT INTO sarcusernote(user_id, xdate, xcontent) VALUES (@user_id, @xdate, @xcontent)" SelectCommand="SELECT sarcusernote.*,(select firstname from sarcuser where id=2) as name, id AS Expr1 FROM sarcusernote WHERE (id = @id)" UpdateCommand="UPDATE sarcusernote SET user_id = @user_id, xdate = @xdate, xcontent = @xcontent WHERE (id = @id)">
        <InsertParameters>
            <asp:Parameter Name="user_id" />
            <asp:Parameter Name="xdate" />
            <asp:ControlParameter ControlID="insert" DefaultValue="%" Name="xcontent" PropertyName="Text" />
        </InsertParameters>
        <SelectParameters>
            <asp:ControlParameter ControlID="GridView1"  DefaultValue="0" Name="id" PropertyName="SelectedValue" />
        </SelectParameters>
        <UpdateParameters>

            <asp:Parameter Name="user_id" />
            <asp:Parameter Name="xdate" />
            <asp:ControlParameter ControlID="update" Name="xcontent" PropertyName="Text" Type="String" DefaultValue="%" />
            <asp:Parameter Name="id" />
        </UpdateParameters>
    </asp:SqlDataSource>

there is no error in the query ... because it's work fine. the problem is when I update or insert some value have these error :

Exception Details: System.InvalidOperationException: Could not find control 'update' in ControlParameter 'xcontent'.

Plz Help

هل كانت مفيدة؟

المحلول

The problem is that your ControlParameter can't find the control that's nested inside a DetailsView (because it is in a different ContentTemplate). There are usually two ways to solve this issue.

Approach #1: Use the "$" symbol to access the nested control.

You can update your markup to something like this:

<asp:ControlParameter ControlID="DetailsView1$update" Name="xcontent" 
    PropertyName="Text" Type="String" DefaultValue="%" />

Using {outerControlID}${innerControlID} will allow your ControlParameter to find the nested control.

Approach #2: Add the parameter in code-behind.

You can programmaticaly add the control to the UpdateParameters collection in your codebehind. This is a bit more of a hack, but I can throw out an example if you need one.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top