Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > GridView, DropDownList, SQLDataSources.... ugh.

Thread Tools

GridView, DropDownList, SQLDataSources.... ugh.

Ryan Marrs
Posts: n/a
Hey guys, I'm working on CommerceStarterKit, modifying it to fit a friend's
needs. There are two issues I'm running into during this, and I'm about

Issue #1: Setting the SelectedValue of the DropDownList in the template
column based on the field ParentID bound to the datagrid.

Issue #2: Getting the SelectedValue to pass to a ControlParameter (or
FormParameter, or ANY Parameter for that matter) for the update call in the

I suppose I could do most of this through the backend, but I'm really
interested in trying this through the controls provided.

Thanks in advance!


<%@ Page Language="vb" MasterPageFile="~/admin.master"
AutoEventWireup="true" CodeFile="admin_categories.aspx.vb"
Inherits="admin_categories" Title="Product Categories"
StylesheetTheme="White" %>
<asp:Content ID="Content1" ContentPlaceHolderID="AdminPlaceHolder"
<h1>Product Categories</h1>
<asp:GridView ID="GridView1" runat="server" AllowSorting="True"
AutoGenerateColumns="False" AutoGenerateDeleteButton="True"
DataKeyNames="CategoryID" DataSourceID="SqlDataSource1">
<asp:CommandField ShowEditButton="True" />
<asp:TemplateField HeaderText="Parent"
<aspropDownList ID="CategoryParentDropDownList"
runat="server" DataTextField="CategoryName" DataValueField="CategoryID"
DataSourceID="sqldsCategories" />
<asp:Label ID="CategoryParent" runat="server"
Text='<%# Bind("Parent") %>'></asp:Label>
<asp:BoundField DataField="ParentID" Visible="False" />
<asp:BoundField DataField="CategoryName"
HeaderText="CategoryName" SortExpression="CategoryName" />
<asp:BoundField DataField="CategoryID"
HeaderText="CategoryID" InsertVisible="False" ReadOnly="True"
SortExpression="CategoryID" />
<asp:HiddenField ID="Something" Value="0" runat="server" />

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:CommerceTemplate %>"
SelectCommand="SELECT C2.[CategoryName] as Parent, C2.[CategoryID] as
ParentID, C1.[CategoryID], C1.[CategoryName] FROM [CMRC_Categories] C1 LEFT
JOIN [CMRC_Categories] C2 ON C1.CategoryParentID=C2.CategoryID"
DeleteCommand="DELETE FROM [CMRC_Categories] WHERE [CategoryID] =
InsertCommand="INSERT INTO [CMRC_Categories] ([CategoryName],
[CategoryParentID]) VALUES (@CategoryName, @CategoryParentID)"
UpdateCommand="UPDATE CMRC_Categories SET CategoryName = @CategoryName,
CategoryParentID = @CategoryParentID WHERE (CategoryID = @CategoryID)">
<asparameter Name="CategoryID" Type="Int32" />
<asparameter Name="CategoryName" Type="String" />
<asp:ControlParameter Name="CategoryID" ControlID="GridView1"
PropertyName="SelectedValue" Type="Int32" />
<asparameter Name="CategoryID" Type="Int32" />
<asparameter Name="CategoryName" Type="String" />
<asparameter Name="CategoryParentID" />
<asp:SqlDataSource ID="sqldsCategories" runat="server"
ConnectionString="<%$ ConnectionStrings:CommerceTemplate %>"
SelectCommand="SELECT [CategoryID], [CategoryName] FROM [CMRC_Categories]"

Reply With Quote
ankit aggarwal
Posts: n/a

*** Sent via Developersdex ***
Reply With Quote

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off