Filter SQLdataSource

S

simonZ

In gridView I have dropdown list :

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ProductID" DataSourceID="SqlDataSource1">

<Columns>

<asp:BoundField DataField="ProductID" HeaderText="ProductID" InsertVisible="False"ReadOnly="True" SortExpression="ProductID" />

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

<asp:TemplateField HeaderText="dropdown">

<ItemTemplate>

<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource2" DataTextField="CustomerName" DataValueField="CustomerID">

</asp:DropDownList>

</ItemTemplate>

</asp:TemplateField>

</Columns>

</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" SelectCommand="SELECT [ProductID], [ProductName] FROM [Alphabetical list of products]"></asp:SqlDataSource>

<asp:SqlDataSource ID="SqlDataSource2" FilterExpression="ProductID='{0}'" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" SelectCommand="SELECT [CustomerName], [CustomerID] FROM [Invoices] " >

<FilterParameters>

<asp:ControlParameter Name="Title" DefaultValue="0"/>

</FilterParameters>

</asp:SqlDataSource>

Now, I would like to filter the sqlDataSource for dropdown list, to fill only that rows into dropdown which has productID equal to the productID of the row, where the dropdown is placed.

(so, sqlDataSource is fileterd dynamically for each row)

I was trying to do that with select parameter but no success. Now, I'm trying to do that with Filter parameter but also got stock.

Any example, idea, help?

Thanks,S
 
S

S. Justin Gengo

Simon,

This walkthrough should help:

http://msdn2.microsoft.com/en-us/library/ms178294(VS.80).aspx

Regards,


--
S. Justin Gengo
Web Developer / Programmer

Free code library:
http://www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche


In gridView I have dropdown list :

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ProductID" DataSourceID="SqlDataSource1">

<Columns>

<asp:BoundField DataField="ProductID" HeaderText="ProductID" InsertVisible="False"ReadOnly="True" SortExpression="ProductID" />

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

<asp:TemplateField HeaderText="dropdown">

<ItemTemplate>

<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource2" DataTextField="CustomerName" DataValueField="CustomerID">

</asp:DropDownList>

</ItemTemplate>

</asp:TemplateField>

</Columns>

</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" SelectCommand="SELECT [ProductID], [ProductName] FROM [Alphabetical list of products]"></asp:SqlDataSource>

<asp:SqlDataSource ID="SqlDataSource2" FilterExpression="ProductID='{0}'" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" SelectCommand="SELECT [CustomerName], [CustomerID] FROM [Invoices] " >

<FilterParameters>

<asp:ControlParameter Name="Title" DefaultValue="0"/>

</FilterParameters>

</asp:SqlDataSource>

Now, I would like to filter the sqlDataSource for dropdown list, to fill only that rows into dropdown which has productID equal to the productID of the row, where the dropdown is placed.

(so, sqlDataSource is fileterd dynamically for each row)

I was trying to do that with select parameter but no success. Now, I'm trying to do that with Filter parameter but also got stock.

Any example, idea, help?

Thanks,S
 
S

simonZ

Thank you Justin, but that is not what I'm looking for.

Example belov shows how to bind dropdown list in edit mode. That is no problem.

In my example I have to show dropdownlist in gridView in normal mode
(there is no eny edit mode or selected column that I could use key columns of gridView)

Any idea?

regards,S
Simon,

This walkthrough should help:

http://msdn2.microsoft.com/en-us/library/ms178294(VS.80).aspx

Regards,


--
S. Justin Gengo
Web Developer / Programmer

Free code library:
http://www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche


In gridView I have dropdown list :

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ProductID" DataSourceID="SqlDataSource1">

<Columns>

<asp:BoundField DataField="ProductID" HeaderText="ProductID" InsertVisible="False"ReadOnly="True" SortExpression="ProductID" />

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

<asp:TemplateField HeaderText="dropdown">

<ItemTemplate>

<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource2" DataTextField="CustomerName" DataValueField="CustomerID">

</asp:DropDownList>

</ItemTemplate>

</asp:TemplateField>

</Columns>

</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" SelectCommand="SELECT [ProductID], [ProductName] FROM [Alphabetical list of products]"></asp:SqlDataSource>

<asp:SqlDataSource ID="SqlDataSource2" FilterExpression="ProductID='{0}'" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" SelectCommand="SELECT [CustomerName], [CustomerID] FROM [Invoices] " >

<FilterParameters>

<asp:ControlParameter Name="Title" DefaultValue="0"/>

</FilterParameters>

</asp:SqlDataSource>

Now, I would like to filter the sqlDataSource for dropdown list, to fill only that rows into dropdown which has productID equal to the productID of the row, where the dropdown is placed.

(so, sqlDataSource is fileterd dynamically for each row)

I was trying to do that with select parameter but no success. Now, I'm trying to do that with Filter parameter but also got stock.

Any example, idea, help?

Thanks,S
 
S

S. Justin Gengo

Simon,

It's the same thing. You just convert the regular mode's column to a template view and do the same things you would have done in edit mode. The two different modes don't matter the technique is the same for either template.

Regards,

--
S. Justin Gengo
Web Developer / Programmer

Free code library:
http://www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche


Thank you Justin, but that is not what I'm looking for.

Example belov shows how to bind dropdown list in edit mode. That is no problem.

In my example I have to show dropdownlist in gridView in normal mode
(there is no eny edit mode or selected column that I could use key columns of gridView)

Any idea?

regards,S
Simon,

This walkthrough should help:

http://msdn2.microsoft.com/en-us/library/ms178294(VS.80).aspx

Regards,


--
S. Justin Gengo
Web Developer / Programmer

Free code library:
http://www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche


In gridView I have dropdown list :

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ProductID" DataSourceID="SqlDataSource1">

<Columns>

<asp:BoundField DataField="ProductID" HeaderText="ProductID" InsertVisible="False"ReadOnly="True" SortExpression="ProductID" />

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

<asp:TemplateField HeaderText="dropdown">

<ItemTemplate>

<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource2" DataTextField="CustomerName" DataValueField="CustomerID">

</asp:DropDownList>

</ItemTemplate>

</asp:TemplateField>

</Columns>

</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" SelectCommand="SELECT [ProductID], [ProductName] FROM [Alphabetical list of products]"></asp:SqlDataSource>

<asp:SqlDataSource ID="SqlDataSource2" FilterExpression="ProductID='{0}'" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" SelectCommand="SELECT [CustomerName], [CustomerID] FROM [Invoices] " >

<FilterParameters>

<asp:ControlParameter Name="Title" DefaultValue="0"/>

</FilterParameters>

</asp:SqlDataSource>

Now, I would like to filter the sqlDataSource for dropdown list, to fill only that rows into dropdown which has productID equal to the productID of the row, where the dropdown is placed.

(so, sqlDataSource is fileterd dynamically for each row)

I was trying to do that with select parameter but no success. Now, I'm trying to do that with Filter parameter but also got stock.

Any example, idea, help?

Thanks,S
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top