views:

2133

answers:

1

I have a very standard Gridview, with Edit and Delete buttons auto-generated. It is bound to a tableadapter which is linked to my "RelationshipTypes" table.

dbo.RelationshipTypes: ID, Name, OriginConfigTypeID, DestinationConfigTypeID

I wish to use a label that will pull the name from the ConfigTypes table, using the "OriginConfigTypeID" and "DestinationTypeID" as the link.

dbo.ConfigTypes: ID, Name

My problem is, I can't automatically generate Edit and Delete buttons using an Inner Join in my dataset. Or can I?

FOllowing is my code:

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
    AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" CssClass="TableList"
    DataKeyNames="ID" DataSourceID="dsRelationShipTypes1">
    <Columns>
        <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
            SortExpression="ID" Visible=False/>
        <asp:TemplateField HeaderText="Origin" SortExpression="OriginCIType_ID">
            <EditItemTemplate>
                &nbsp;<asp:DropDownList Enabled=true ID="DropDownList2" runat="server" DataSourceID="dsCIType1"
                    DataTextField="Name" DataValueField="ID" SelectedValue='<%# Bind("OriginCIType_ID") %>'>
                </asp:DropDownList>
            </EditItemTemplate>
            <ItemTemplate>
                &nbsp;
                <asp:Label ID="Label2" runat="server" Text='<%# Bind("OriginCIType_ID") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Name" SortExpression="Name">
            <EditItemTemplate>
                <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label3" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Destination" SortExpression="DestinationCIType_ID">
            <EditItemTemplate>
                <asp:DropDownList ID="DropDownList3" runat="server" DataSourceID="dsCIType1" DataTextField="Name"
                    DataValueField="ID" SelectedValue='<%# Bind("DestinationCIType_ID") %>'>
                </asp:DropDownList>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text='<%# Bind("DestinationCIType_ID") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

So I did try to create my own edit and delete buttons, but kept receiving the error "cannot find update method" or something similar. Do I have to manually code the delete and update methods in my code-behind?

A: 

You have to tell either the ObjectDataSource what object to use or the SQLDataSource what stored proc to use. Use the "UpdateMethod" attribute.

craigmoliver