Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #11 (permalink)  
Old March 13th, 2009, 10:45 AM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Yes, obviously I am talking aonly about binding in Edit mode here.

I know my solution is correct. I may have not have given you the exactly right column name to Bind to. It is confusing because you haven't provided the schema (column names) of your tables here, so I'm just guessing at that.

You might have to use Bind("Name") or something else, depending on what your column names are.

I am going to post the known working example I came up with to prove this concept. Maybe you can take it from there.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
  #12 (permalink)  
Old March 13th, 2009, 11:04 AM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default Working Northwind Example

HTML Code:
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
   <title>GridView DroopDown Edit</title>
</head>
<body>
   <form id="form1" runat="server">
      <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
         DataKeyNames="ProductID" DataSourceID="SqlDataSource1">
         <Columns>
            <asp:CommandField ShowEditButton="True" />
            <asp:BoundField DataField="ProductID" HeaderText="ProductID"
               InsertVisible="False" ReadOnly="True" SortExpression="ProductID" />
            <asp:TemplateField HeaderText="Category">
               <EditItemTemplate>
                  <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource2"
                     DataTextField="CategoryName" DataValueField="CategoryID" SelectedValue='<%# Bind("CategoryID") %>'>
                  </asp:DropDownList>
                  <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
                     SelectCommand="SELECT [CategoryID], [CategoryName] FROM [Categories]">
                  </asp:SqlDataSource>
               </EditItemTemplate>
               <ItemTemplate>
                  <asp:Literal ID="Literal1" runat="server" Text='<%# Eval("CategoryName") %>' />
               </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="ProductName" HeaderText="ProductName"
               SortExpression="ProductName" />
         </Columns>
      </asp:GridView>
      <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="CompareAllValues"
         ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
         OldValuesParameterFormatString="original_{0}"
         SelectCommand="SELECT Products.ProductID, Products.ProductName, Products.CategoryID, Categories.CategoryName FROM Categories INNER JOIN Products ON Categories.CategoryID = Products.CategoryID"
         DeleteCommand="DELETE FROM [Products] WHERE [ProductID] = @original_ProductID AND (([CategoryID] = @original_CategoryID) OR ([CategoryID] IS NULL AND @original_CategoryID IS NULL)) AND [ProductName] = @original_ProductName"
         InsertCommand="INSERT INTO [Products] ([CategoryID], [ProductName]) VALUES (@CategoryID, @ProductName)"
         UpdateCommand="UPDATE [Products] SET [CategoryID] = @CategoryID, [ProductName] = @ProductName WHERE [ProductID] = @original_ProductID AND (([CategoryID] = @original_CategoryID) OR ([CategoryID] IS NULL AND @original_CategoryID IS NULL)) AND [ProductName] = @original_ProductName">
         <DeleteParameters>
            <asp:Parameter Name="original_ProductID" Type="Int32" />
            <asp:Parameter Name="original_CategoryID" Type="Int32" />
            <asp:Parameter Name="original_ProductName" Type="String" />
         </DeleteParameters>
         <UpdateParameters>
            <asp:Parameter Name="CategoryID" Type="Int32" />
            <asp:Parameter Name="ProductName" Type="String" />
            <asp:Parameter Name="original_ProductID" Type="Int32" />
            <asp:Parameter Name="original_CategoryID" Type="Int32" />
            <asp:Parameter Name="original_ProductName" Type="String" />
         </UpdateParameters>
         <InsertParameters>
            <asp:Parameter Name="CategoryID" Type="Int32" />
            <asp:Parameter Name="ProductName" Type="String" />
         </InsertParameters>
      </asp:SqlDataSource>
   </form>
</body>
</html>
 
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
The Following User Says Thank You to Lee Dumond For This Useful Post:
RushNP774 (March 15th, 2009)
  #13 (permalink)  
Old March 13th, 2009, 12:53 PM
Authorized User
 
Join Date: Mar 2009
Posts: 23
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Sorry for the misunderstanding Lee. It was late and I wasn't thinking clearly. Thanks for your code snippet. I'll play around with it until I get it to work, and will let you know what I was doing wrong. Thanks again!
  #14 (permalink)  
Old March 13th, 2009, 01:06 PM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

If you have the Northwind database and can connect to it, and define "NorthwindConnectionString" as the connection string name, then you should be able to paste this straight into an .aspx file and run it.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
  #15 (permalink)  
Old March 15th, 2009, 02:57 AM
Authorized User
 
Join Date: Mar 2009
Posts: 23
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Lee, I played around with it for a long time and got everything to work, until I restarted my project... I keep getting this error (and it happened before I got it work as well. I just don't remember what I changed):

DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'CategoryName'

When I get to this line:

Code:
<asp:Literal ID="Literal1" runat="server" Text='<%# Eval("CategoryName") %>'/>
"CategoryName" is the field in my [Categories] table that holds the description of the category. I have Categories.CategoryName pulling correctly from my SelectStatement, so it seems odd that the Eval statement can't find it.

The site runs fine when I replace the Eval statement with ActivityCategoryID from my [Activities] table, but the GridView just shows the ID and not the name.

Any ideas?

Last edited by RushNP774; March 15th, 2009 at 04:03 AM..
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
gridview using dropdown komalpriya ASP.NET 2.0 Professional 1 November 1st, 2007 12:34 AM
gridview with a dropdown list paullam71 ASP.NET 2.0 Basics 0 July 22nd, 2007 09:43 AM
Dropdown Box problem migarich ASP.NET 1.0 and 1.1 Basics 3 March 22nd, 2006 10:28 AM
dropdown list not selecting record on page load whyulil ASP.NET 1.0 and 1.1 Basics 1 September 8th, 2004 08:29 AM
update dropdown values mateenmohd SQL Server 2000 0 October 9th, 2003 03:23 AM



All times are GMT -4. The time now is 09:01 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.