Wednesday, March 21, 2012

Populating a DataGrid with a Stored Procedure based on ddl values

Hello All -

First off, I am a complete newbie.

I have created a page with 5 dropdownlists that I populated using stored procedures.

Question one:

How Do I display a default value for these Dropdowns?

I have configured a DataGrid using another Stored Procedure.

Question 2:

How Do I populate the DG with the values specified within the 5 dropdownlists using a stored procedure?

Here is a copy of the current aspx page.

<%@dotnet.itags.org.PageLanguage="VB"MasterPageFile="~/MasterPage.master"Title="CTM PreRunbook" %>

<asp:ContentID="Content1"ContentPlaceHolderID="ContentPlaceHolder1"Runat="Server">

<table><tr><thalign="center"colspan="3"style="vertical-align: middle; text-align: center"valign="middle">

<asp:LabelID="Label1"runat="server"Font-Size="Large"Text="Data Feed Query"></asp:Label> </th></tr>

<tr>

<th>

Application Name:</th>

<tdalign="right"style="vertical-align: top; text-align: left">

<tdstyle="width: 31px">

<asp:DropDownListID="ddlAppName"runat="server"AutoPostBack="True"DataSourceID="SqlDataSource1"DataTextField="AppName"DataValueField="AppName">

<asp:ListItem>- Select -</asp:ListItem>

</asp:DropDownList><asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ ConnectionStrings:PreRunbookConnectionString %>"

SelectCommand="spGet_AppName"SelectCommandType="StoredProcedure"></asp:SqlDataSource>

</td></tr>

<tr>

<th>

Data Feed Name:</th>

<tdalign="right"style="vertical-align: top; text-align: left">

<tdstyle="width: 31px; text-align: left;">

<asp:DropDownListID="ddlDataFeedName"runat="server"AutoPostBack="True"DataSourceID="SqlDataSourceDependantFeeds"DataTextField="FeedName"DataValueField="FeedName">

</asp:DropDownList><asp:SqlDataSourceID="SqlDataSourceDependantFeeds"runat="server"

ConnectionString="<%$ ConnectionStrings:PreRunbookConnectionString %>"SelectCommand="spGet_FeedNames"

SelectCommandType="StoredProcedure"></asp:SqlDataSource>

</td></tr>

<tr>

<th>

Account:</th>

<tdalign="right"style="vertical-align: top; text-align: left">

<tdstyle="width: 31px">

<asp:DropDownListID="ddlAccount"runat="server"AutoPostBack="True"DataSourceID="SqlDataSourceServiceAccount"DataTextField="ServiceAccounts"DataValueField="ServiceAccounts">

</asp:DropDownList><asp:SqlDataSourceID="SqlDataSourceServiceAccount"runat="server"

ConnectionString="<%$ ConnectionStrings:PreRunbookConnectionString %>"SelectCommand="spGetDistinctServiceAccounts"

SelectCommandType="StoredProcedure"></asp:SqlDataSource>

</td></tr>

<tr>

<th>

Platform:</th>

<tdalign="right"style="vertical-align: top; text-align: left">

<tdstyle="width: 31px; text-align: left;">

<asp:DropDownListID="ddlPlatform"runat="server"AutoPostBack="True"DataSourceID="SqlDataSourcePlatform"DataTextField="Platform"DataValueField="Platform">

</asp:DropDownList><asp:SqlDataSourceID="SqlDataSourcePlatform"runat="server"ConnectionString="<%$ ConnectionStrings:PreRunbookConnectionString %>"

SelectCommand="spGet_Platform"SelectCommandType="StoredProcedure"></asp:SqlDataSource>

</td></tr>

<tr>

<th>

Scheduled Run Days:</th>

<tdalign="right"style="vertical-align: top; text-align: left">

<tdstyle="width: 31px">

<asp:DropDownListID="ddlSchedRunDays"runat="server"AutoPostBack="True"DataSourceID="SqlDataSourceSchedRunDays"DataTextField="ScheduledRunDays"DataValueField="ScheduledRunDays">

</asp:DropDownList><asp:SqlDataSourceID="SqlDataSourceSchedRunDays"runat="server"

ConnectionString="<%$ ConnectionStrings:PreRunbookConnectionString %>"SelectCommand="spGet_ScheduledRunDays"

SelectCommandType="StoredProcedure"></asp:SqlDataSource>

</td></tr>

</Table>

<table>

<tr>

<tdstyle="width: 100px"align="center">

<asp:ButtonID="btnFilter"runat="server"Text="Filter"/></td>

<tdstyle="width: 100px">

<asp:ButtonID="btnReset"runat="server"Text="Reset"/></td>

</tr>

<tr>

<tdcolspan="2"align="center">

<asp:ButtonID="btnShowAllDataFeeds"runat="server"Text="Show All Data Feeds"/></td>

</tr>

</table>

<br/>

<asp:GridViewID="GridView1"runat="server"AllowPaging="True"AllowSorting="True"

AutoGenerateColumns="False"DataSourceID="SqlDataSourceGridView">

</asp:GridView>

<asp:SqlDataSourceID="SqlDataSourceGridView"runat="server"ConnectionString="<%$ ConnectionStrings:PreRunbookConnectionString %>"

SelectCommand="spFilterByServAcct"SelectCommandType="StoredProcedure">

<SelectParameters>

<asp:FormParameterFormField="ServiceAccounts"Name="ServAcct"

Type="String"/>

</SelectParameters>

</asp:SqlDataSource>

<br>

</asp:Content>

Thanks ,

Pat

here is the best example that describes your needs

http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/data/sqldatasource.aspx

0 comments:

Post a Comment