C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Grid view with edit option with combo


Posted Date: 19 Sep 2008    Resource Type: Code Snippets    Category: ASP.NET GridView

Posted By: AbidiP       Member Level: Gold
Rating:     Points: 10



This example will display a grid with edit option, on edit of item complete row is got edited in the form of TEXT BOX and COMBO BOX


Just you have to copy this in your aspx file.

i have used 2 data source item 1st for displaying the information in the grid and update the information & other display the information into grid Combo box



< asp:SqlDataSource ID="productsDataSource"
Runat="server" SelectCommand="SELECT Products.ProductID, Products.ProductName, Products.CategoryID, Categories.CategoryName FROM Products INNER JOIN Categories ON Products.CategoryID = Categories.CategoryID"
UpdateCommand="UPDATE Products SET ProductName = @ProductName, CategoryID = @CategoryID WHERE (ProductID = @ProductID)"
ConnectionString="
<%$ ConnectionStrings:NorthwindConnectionString %>
">
< UpdateParameters >
< asp:Parameter Type="String" Name="ProductName" > </asp:Parameter >
< asp:Parameter Type="Int32" Name="CategoryID"> </asp:Parameter >
< asp:Parameter Name="ProductID" ></asp:Parameter >
</UpdateParameters >
</asp:SqlDataSource>
<asp:SqlDataSource ID="categoryDataSource" Runat="server"
SelectCommand="SELECT CategoryID, CategoryName FROM Categories ORDER BY CategoryName"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"> </asp:SqlDataSource>


this is the grid view

 





<asp:GridView ID="GridView4" Runat="server" DataSourceID="productsDataSource" DataKeyNames="ProductID"
AutoGenerateColumns="False" AllowPaging="True" BorderWidth="1px" BackColor="White" CellPadding="3" BorderStyle="None" BorderColor="#CCCCCC">
<FooterStyle ForeColor="#000066" BackColor="White"></FooterStyle>
<PagerStyle ForeColor="#000066" HorizontalAlign="Left" BackColor="White"></PagerStyle>
<HeaderStyle ForeColor="White" Font-Bold="True" BackColor="#006699"></HeaderStyle>
<Columns>
<asp:CommandField ShowEditButton="True"></asp:CommandField>
<asp:BoundField ReadOnly="True" HeaderText="ProductID" InsertVisible="False" DataField="ProductID" SortExpression="ProductID"></asp:BoundField>



<asp:BoundField HeaderText="ProductName" DataField="ProductName" SortExpression="ProductName"></asp:BoundField>
<asp:TemplateField SortExpression="CategoryName" HeaderText="CategoryName">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" Runat="server" DataSourceID="categoryDataSource"
DataTextField="CategoryName" DataValueField="CategoryID" SelectedValue='<%# Bind("CategoryID") %>'>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label Runat="server" Text='<%# Bind("CategoryName") %>' ID="Label1"></asp:Label>
</ItemTemplate >
</asp:TemplateField>
</Columns>
<SelectedRowStyle ForeColor="White" Font-Bold="True" BackColor="#669999"></SelectedRowStyle>
<RowStyle ForeColor="#000066"></RowStyle>
</asp:GridView>



NOTE: i have used the Northwind database. you might have to check the connection string of the DataSource.





Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Gridview with combo box  .  GridView  .  Grid with edit  .  Grid with combo box  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: How to get Grid with Combobox
Previous Resource: Binding Gridvew Using LINQ
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET GridView


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

efax

Contact Us    Privacy Policy    Terms Of Use