Solved

Gridview select from dropdownlist

Posted on 2009-07-11
17
272 Views
Last Modified: 2012-05-07
Yes I am trying to select the date to change gridview.

how can i pass the parameter @Date  to if I selectvalue from dropdownlist.
Dropdownlist has the date as the selected item but i am selecting the value, I just need to pass the value to the @Date in the gridview.


''###############   spGetEventFrontpage  '''
(@Date As datetime)
As
SELECT A.Pk_Events,
            A.Date,
            A.Description,
            A.EventTypes,
            B.Startday,
B.Month,
B.Enddate
FROM [dbo].[Events] A
Join [dbo].[monthC] B On A.date = date
 WHERE @Date between  B.Startday and B.Enddate  and
 A.date between B.Startday and B.Enddate

''################# end stored procedure ###########
<asp:DropDownList ID="DropDownList1" AutoPostBack="True" runat="server" 

         DataSourceID="SqlDataSource2" DataTextField="Month" DataValueField="Startday">

    </asp:DropDownList>

     <asp:SqlDataSource ID="SqlDataSource2" runat="server" 

         ConnectionString="<%$ ConnectionStrings:tConnectionString %>" 

         SelectCommand="select * from Monthc">

         <SelectParameters>

<asp:ControlParameter ControlID="Gridview1"

DefaultValue="@Date" Name="Mid"

PropertyName="SelectedValue" Type="String" />

</SelectParameters>

     </asp:SqlDataSource>

<br />

    <asp:Label ID="Label1" runat="server" CssClass="header1" ></asp:Label></div>

 <br />   <asp:GridView ID="GridView1" runat="server" AllowPaging="True"   Width="620px" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged1"

            AllowSorting="True" AutoGenerateColumns="False" CellPadding="4"  Font-Size="Small"

            DataKeyNames="Pk_Events" DataSourceID="SqlDataSource1" ForeColor="#333333" 

            GridLines="None">

            <RowStyle BackColor="#D0C0DD" />

            

            <Columns>

                <asp:BoundField DataField="Pk_Events" HeaderText="Pk_Events" 

                    InsertVisible="False" ReadOnly="True" ShowHeader="False" 

                    SortExpression="Pk_Events" Visible="False" />

                <asp:BoundField DataField="Date" HeaderText="DATE" DataFormatString="{0:dd MMMM yyyy}" SortExpression="date"  />

                <asp:BoundField DataField="enddate"  Visible="false" DataFormatString="{0:dd MMMM yyyy}"    SortExpression="enddate" />

                <asp:BoundField DataField="Description" HeaderText="Details" 

                    SortExpression="Description" />

                <asp:TemplateField HeaderStyle-CssClass="shoesB"  HeaderImageUrl="~/TrendEvents/images/TNM_pick.gif">                 

                    <ItemTemplate>

                        <asp:Image ID="Image1" CssClass="shoesB1" runat="server" ImageUrl="~/TrendEvents/images/TNM_pick2.gif" />

                    </ItemTemplate>

                </asp:TemplateField>

                <asp:BoundField DataField="NEIGHBORHOOD" HeaderText="NEIGHBORHOOD" 

                    SortExpression="NEIGHBORHOOD" />

                <asp:BoundField DataField="EventTypes" Visible="false" HeaderText="EventTypes" 

                    SortExpression="EventTypes" />

                <asp:BoundField DataField="Details" Visible="false" HeaderText="DETAILS" 

                    SortExpression="Details" />

            </Columns>

            <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />

            <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />

            <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />

            <HeaderStyle BackColor="#000000" Font-Bold="True" ForeColor="White" />

            <EditRowStyle BackColor="#7C6F57" />

            <AlternatingRowStyle BackColor="White" />

        </asp:GridView>

        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 

            ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 

            SelectCommand="spGetEventFrontpage" SelectCommandType="StoredProcedure">

        </asp:SqlDataSource>

Open in new window

0
Comment
Question by:sevensnake77
  • 9
  • 8
17 Comments
 
LVL 15

Expert Comment

by:jinal
ID: 24829575
Hello ,

As i understand from your source that you have to dispaly data in GridView and Date value pass from DropDownList.

In that case you have to configure SqlDataSource1 for SelectParameter.
0
 
LVL 15

Expert Comment

by:jinal
ID: 24829594
It should be something like this.

<asp:DropDownList ID="DropDownList1" AutoPostBack="True" runat="server" DataSourceID="SqlDataSource2"

        DataTextField="Month" DataValueField="Startday">

    </asp:DropDownList>

    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:tConnectionString %>"

        SelectCommand="select * from Monthc">        

    </asp:SqlDataSource>

    <br />

    <asp:Label ID="Label1" runat="server" CssClass="header1"></asp:Label></div>

    <br />

    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" Width="620px" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged1"

        AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" Font-Size="Small"

        DataKeyNames="Pk_Events" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None">

        <RowStyle BackColor="#D0C0DD" />

        <Columns>

            <asp:BoundField DataField="Pk_Events" HeaderText="Pk_Events" InsertVisible="False"

                ReadOnly="True" ShowHeader="False" SortExpression="Pk_Events" Visible="False" />

            <asp:BoundField DataField="Date" HeaderText="DATE" DataFormatString="{0:dd MMMM yyyy}"

                SortExpression="date" />

            <asp:BoundField DataField="enddate" Visible="false" DataFormatString="{0:dd MMMM yyyy}"

                SortExpression="enddate" />

            <asp:BoundField DataField="Description" HeaderText="Details" SortExpression="Description" />

            <asp:TemplateField HeaderStyle-CssClass="shoesB" HeaderImageUrl="~/TrendEvents/images/TNM_pick.gif">

                <ItemTemplate>

                    <asp:Image ID="Image1" CssClass="shoesB1" runat="server" ImageUrl="~/TrendEvents/images/TNM_pick2.gif" />

                </ItemTemplate>

            </asp:TemplateField>

            <asp:BoundField DataField="NEIGHBORHOOD" HeaderText="NEIGHBORHOOD" SortExpression="NEIGHBORHOOD" />

            <asp:BoundField DataField="EventTypes" Visible="false" HeaderText="EventTypes" SortExpression="EventTypes" />

            <asp:BoundField DataField="Details" Visible="false" HeaderText="DETAILS" SortExpression="Details" />

        </Columns>

        <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />

        <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />

        <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />

        <HeaderStyle BackColor="#000000" Font-Bold="True" ForeColor="White" />

        <EditRowStyle BackColor="#7C6F57" />

        <AlternatingRowStyle BackColor="White" />

    </asp:GridView>

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"

        SelectCommand="spGetEventFrontpage" SelectCommandType="StoredProcedure">

        <SelectParameters>

            <asp:ControlParameter ControlID="DropDownList1" PropertyName="SelectedValue" />

        </SelectParameters>

    </asp:SqlDataSource>

Open in new window

0
 
LVL 9

Author Comment

by:sevensnake77
ID: 24829612
getting this error for parameter
 
Procedure spGetEventFrontpage has no parameters and arguments were supplied
0
 
LVL 15

Expert Comment

by:jinal
ID: 24829619

 <asp:DropDownList ID="DropDownList1" AutoPostBack="True" runat="server" DataSourceID="SqlDataSource2"

        DataTextField="Month" DataValueField="Startday">

    </asp:DropDownList>

    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:tConnectionString %>"

        SelectCommand="select * from Monthc">        

    </asp:SqlDataSource>

    <br />

    <asp:Label ID="Label1" runat="server" CssClass="header1"></asp:Label></div>

    <br />

    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" Width="620px" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged1"

        AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" Font-Size="Small"

        DataKeyNames="Pk_Events" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None">

        <RowStyle BackColor="#D0C0DD" />

        <Columns>

            <asp:BoundField DataField="Pk_Events" HeaderText="Pk_Events" InsertVisible="False"

                ReadOnly="True" ShowHeader="False" SortExpression="Pk_Events" Visible="False" />

            <asp:BoundField DataField="Date" HeaderText="DATE" DataFormatString="{0:dd MMMM yyyy}"

                SortExpression="date" />

            <asp:BoundField DataField="enddate" Visible="false" DataFormatString="{0:dd MMMM yyyy}"

                SortExpression="enddate" />

            <asp:BoundField DataField="Description" HeaderText="Details" SortExpression="Description" />

            <asp:TemplateField HeaderStyle-CssClass="shoesB" HeaderImageUrl="~/TrendEvents/images/TNM_pick.gif">

                <ItemTemplate>

                    <asp:Image ID="Image1" CssClass="shoesB1" runat="server" ImageUrl="~/TrendEvents/images/TNM_pick2.gif" />

                </ItemTemplate>

            </asp:TemplateField>

            <asp:BoundField DataField="NEIGHBORHOOD" HeaderText="NEIGHBORHOOD" SortExpression="NEIGHBORHOOD" />

            <asp:BoundField DataField="EventTypes" Visible="false" HeaderText="EventTypes" SortExpression="EventTypes" />

            <asp:BoundField DataField="Details" Visible="false" HeaderText="DETAILS" SortExpression="Details" />

        </Columns>

        <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />

        <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />

        <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />

        <HeaderStyle BackColor="#000000" Font-Bold="True" ForeColor="White" />

        <EditRowStyle BackColor="#7C6F57" />

        <AlternatingRowStyle BackColor="White" />

    </asp:GridView>

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"

        SelectCommand="spGetEventFrontpage" SelectCommandType="StoredProcedure">

        <SelectParameters>

            <asp:ControlParameter ControlID="DropDownList1" DbType="DateTime" PropertyName="SelectedValue" Name="@Date" DefaultValue="07/01/2009"  />

        </SelectParameters>

    </asp:SqlDataSource>

Open in new window

0
 
LVL 9

Author Comment

by:sevensnake77
ID: 24829641
Procedure or function 'sptkGetdate' expects parameter '@Date', which was not supplied.
 
 

Alter PROCEDURE [dbo].[sptkGetdate]
(@Date As datetime)
As
SELECT A.Pk_Events,
A.Date,
A.Description,
A.EventTypes,
B.Startday,
B.Month,
B.Enddate
FROM [dbo].[Events] A
Join [dbo].[monthC] B On A.date = date
WHERE @Date between B.Startday and B.Enddate and
A.date between B.Startday and B.Enddate
Order by A.date
0
 
LVL 15

Expert Comment

by:jinal
ID: 24829659
What is your stored procedure name ? Is it spGetEventFrontpage or sptkGetdate .

In attached code i used spGetEventFrontpage so ...

<asp:DropDownList ID="DropDownList1" AutoPostBack="True" runat="server" DataSourceID="SqlDataSource2"

        DataTextField="Month" DataValueField="Startday">

    </asp:DropDownList>

    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:tConnectionString %>"

        SelectCommand="select * from Monthc">        

    </asp:SqlDataSource>

    <br />

    <asp:Label ID="Label1" runat="server" CssClass="header1"></asp:Label></div>

    <br />

    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" Width="620px" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged1"

        AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" Font-Size="Small"

        DataKeyNames="Pk_Events" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None">

        <RowStyle BackColor="#D0C0DD" />

        <Columns>

            <asp:BoundField DataField="Pk_Events" HeaderText="Pk_Events" InsertVisible="False"

                ReadOnly="True" ShowHeader="False" SortExpression="Pk_Events" Visible="False" />

            <asp:BoundField DataField="Date" HeaderText="DATE" DataFormatString="{0:dd MMMM yyyy}"

                SortExpression="date" />

            <asp:BoundField DataField="enddate" Visible="false" DataFormatString="{0:dd MMMM yyyy}"

                SortExpression="enddate" />

            <asp:BoundField DataField="Description" HeaderText="Details" SortExpression="Description" />

            <asp:TemplateField HeaderStyle-CssClass="shoesB" HeaderImageUrl="~/TrendEvents/images/TNM_pick.gif">

                <ItemTemplate>

                    <asp:Image ID="Image1" CssClass="shoesB1" runat="server" ImageUrl="~/TrendEvents/images/TNM_pick2.gif" />

                </ItemTemplate>

            </asp:TemplateField>

            <asp:BoundField DataField="NEIGHBORHOOD" HeaderText="NEIGHBORHOOD" SortExpression="NEIGHBORHOOD" />

            <asp:BoundField DataField="EventTypes" Visible="false" HeaderText="EventTypes" SortExpression="EventTypes" />

            <asp:BoundField DataField="Details" Visible="false" HeaderText="DETAILS" SortExpression="Details" />

        </Columns>

        <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />

        <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />

        <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />

        <HeaderStyle BackColor="#000000" Font-Bold="True" ForeColor="White" />

        <EditRowStyle BackColor="#7C6F57" />

        <AlternatingRowStyle BackColor="White" />

    </asp:GridView>

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"

        SelectCommand="spGetEventFrontpage" SelectCommandType="StoredProcedure">

        <SelectParameters>

            <asp:ControlParameter ControlID="DropDownList1" DbType="DateTime" PropertyName="SelectedValue" Name="Date" DefaultValue="07/01/2009"  />

        </SelectParameters>

    </asp:SqlDataSource>

Open in new window

0
 
LVL 9

Author Comment

by:sevensnake77
ID: 24829674
Yes but it is sptkGetdate
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 24829681
Maybe when its first loading the Grid its looking for a date. and it cannot find it.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 15

Expert Comment

by:jinal
ID: 24829706
Can you please put date value from database.

b'coz in database Dateonly not going to compare . Instead of that long  date compare and that cause the problem.
0
 
LVL 15

Expert Comment

by:jinal
ID: 24829720
Please put record over here.
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 24829725
you mean like this 7/11/2009
 
instead of this.
7/11/2009 12:00:00 AM
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 24829743
9 2009-07-10 00:00:00.000 this is only a test of what asdsd test 2009-07-01 00:00:00.000 July 2009-07-31 23:59:00.000 wq
11 2009-07-10 00:00:00.000 this is only a test of what sdfs test 2009-07-01 00:00:00.000 July 2009-07-31 23:59:00.000 wq
0
 
LVL 15

Expert Comment

by:jinal
ID: 24829833
For example

July 2009-07-31 23:59:00.000 if you compare this witj 2009-07-31 09:34:00.000 it gives you wrong answer.

It is not equal stored procedure.
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 24830717
right but the value in the dropdownlist is
<option value="1/1/2009 12:00:00 AM">January</option>
 
and if I put this in the stored procedure
 
Alter PROCEDURE [dbo].[sptkGetdate]
(@Date As datetime)
As
SELECT A.Pk_Events,
A.Date,
A.Description,
A.EventTypes,
B.Startday,
B.Month,
B.Enddate
FROM [dbo].[Events] A
Join [dbo].[monthC] B On A.date = date
WHERE '1/1/2009 12:00:00 AM' between B.Startday and B.Enddate and
A.date between B.Startday and B.Enddate
Order by A.date  
 
it works
0
 
LVL 15

Accepted Solution

by:
jinal earned 500 total points
ID: 24830909
Hello ,

Try this out . Make another test page and just try this out.

<asp:DropDownList ID="DropDownList1" AutoPostBack="True" runat="server" DataSourceID="SqlDataSource2"

        DataTextField="Month" DataValueField="Startday">

    </asp:DropDownList>

    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:tConnectionString %>"

        SelectCommand="select * from Monthc">        

    </asp:SqlDataSource>

    <br />

    <asp:Label ID="Label1" runat="server" CssClass="header1"></asp:Label></div>

    <br />

    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" Width="620px" AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" Font-Size="Small" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None">

        <RowStyle BackColor="#D0C0DD" />

        <Columns>

            <asp:BoundField DataField="Pk_Events" HeaderText="Pk_Events" InsertVisible="False"

                ReadOnly="True" ShowHeader="False" SortExpression="Pk_Events" Visible="False" />

            <asp:BoundField DataField="Date" HeaderText="DATE" DataFormatString="{0:dd MMMM yyyy}"

                SortExpression="date" />

            <asp:BoundField DataField="enddate" Visible="false" DataFormatString="{0:dd MMMM yyyy}"

                SortExpression="enddate" />

            <asp:BoundField DataField="Description" HeaderText="Details" SortExpression="Description" />

            <asp:TemplateField HeaderStyle-CssClass="shoesB" HeaderImageUrl="~/TrendEvents/images/TNM_pick.gif">

                <ItemTemplate>

                    <asp:Image ID="Image1" CssClass="shoesB1" runat="server" ImageUrl="~/TrendEvents/images/TNM_pick2.gif" />

                </ItemTemplate>

            </asp:TemplateField>

            <asp:BoundField DataField="NEIGHBORHOOD" HeaderText="NEIGHBORHOOD" SortExpression="NEIGHBORHOOD" />

            <asp:BoundField DataField="EventTypes" Visible="false" HeaderText="EventTypes" SortExpression="EventTypes" />

            <asp:BoundField DataField="Details" Visible="false" HeaderText="DETAILS" SortExpression="Details" />

        </Columns>

        <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />

        <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />

        <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />

        <HeaderStyle BackColor="#000000" Font-Bold="True" ForeColor="White" />

        <EditRowStyle BackColor="#7C6F57" />

        <AlternatingRowStyle BackColor="White" />

    </asp:GridView>

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"

        SelectCommand="sptkGetdate" SelectCommandType="StoredProcedure">

        <SelectParameters>

            <asp:ControlParameter ControlID="DropDownList1" DbType="DateTime" PropertyName="SelectedValue" Name="Date" DefaultValue="01/01/2009 12:00:00 AM"  />

        </SelectParameters>

    </asp:SqlDataSource>

Open in new window

0
 
LVL 9

Author Comment

by:sevensnake77
ID: 24831591
Procedure sptkGetdate has no parameters and arguments were supplied. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

0
 
LVL 9

Author Closing Comment

by:sevensnake77
ID: 31602384
it works thanks
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Class Library Dynamics For Connectstring Information 2 21
Problem to error 4 43
What .NET URL re-routing tool did I use? 2 36
how to read json value 2 30
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now