Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a gridview, i not sure how to code for updating row of a gridview that is make up of the 4 table and retrieve them and update them each new value to it respective database table?

so in the back end code how should call it in rowupdating

the database make up the gridview is make up of 4 different table

which mean this code in aspx


ASP.NET
<asp:SqlDataSource ID="SqlDataSource4" runat="server" 
        ConnectionString="<%$ ConnectionStrings:Proj %>" 
        SelectCommand="SELECT image.img, style.styleName, Card.CardName, Card.CardID, Card.price, backViewImg.backViewImg FROM backViewImg INNER JOIN Card ON backViewImg.backViewImgID = Card.backViewImgID INNER JOIN image ON Card.imgID = image.imgID INNER JOIN style ON Card.styleID = style.styleID">
    </asp:SqlDataSource>
Posted

1 solution

Herez the sample to embed 2 tables. You can extend it to 4 tables.

XML
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" AllowPaging="True" AllowSorting="True" AutoGenerateEditButton="True" DataKeyNames="pk_as_item_id">
<Columns>
<asp:BoundField ReadOnly="true" DataField="pk_as_item_id" HeaderText="ID" SortExpression="pk_as_item_id" />
<asp:BoundField DataField="description" HeaderText="Description" SortExpression="description" />
<asp:TemplateField HeaderText="Location" SortExpression="loca_description" >
<EditItemTemplate>
<asp:DropDownList ID="ddl_location" runat="server" DataSourceID="SqlDataSource2" DataValueField="pk_as_loca_id" DataTextField="loca_description" >
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lbl_location" runat="server" Text='<%# Bind("loca_description") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Personal %>"
SelectCommand="SELECT [pk_as_item_id], [description], [fk_as_loca_id], [pk_as_loca_id], [loca_description] FROM [ITEMS], [LOCATIONS] WHERE [fk_as_loca_id] = [pk_as_loca_id]"
UpdateCommand="UPDATE [ITEMS] SET [pk_as_item_id] = @pk_as_item_id, [description] = @description, [fk_as_loca_id] = ???????  WHERE [pk_as_item_id] = @pk_as_item_id">
</asp:SqlDataSource>

<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:Personal %>"
SelectCommand="SELECT [pk_as_loca_id], [loca_description] FROM [LOCATIONS]">
</asp:SqlDataSource
 
Share this answer
 
Comments
cutexxbaby 7-Jan-12 1:37am    
thereby the aspx.cs do i need to write any update code?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900