i have gridview bind with 1 datasource to get all data, but now i want to add 1 more dropdown which need to get the data from other table. Did anyone have idea how to do this? in VB, thanks
Add a new SqlDataSource (or similar) to select the data from the other table and then add a template field n your GridView to display the DropDownList with the data from the new DataSource control:
thanks for your suggestion, i try your way but i keep getting Could not find any attribute 'appendDataBoundItems' of element 'DropDownList' and also error when i write for new datasource??
now i try to create 2 set of return result in my stored procedure, but them i bind it to the dropdownlist, it keep prompt "DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'dytValue'. dytValue is the 2nd set of data in my
stored procedure, do you know who to fix this?
Why do you return two datasets from one stored procedure instead of having two separate stored procedures? You can only bind your GridView to one DataSet.
because i need to bind 2 different result in 1 gridview, do you have any idea doing that? i have my sproc as below
from 1st return set, i will need to bind all result which with where cause, then for the 2nd return set i need bind all studName which already paid in the drop down list.
Now I already can display all value in the gridview, but i having problem to bind the data in the dropdownlist for user to select.
please help if you have idea on how to do that. Thanks in advance.
I don't really understand...do you want to display the students that have not paid in the dropdownlist? In that case bind the DropDownList to a SqlDataSource:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" SelectCommand="SELECT UserName as FullName FROM StudentTbl WHERE Paid <> '0'" .../>
Sorry, i currently dont have the coding to test.. only can try again tomorrow. but the method you mention i've try this afternoon, but it seems like canot direct bind the sqlDataSource to dropdownlist in gridview, will it show error because of the gridview
already bind to other datasource?
aoshi_kh
Member
123 Points
331 Posts
how to bind dropdownlist datasource to different sql select statement?
Apr 09, 2012 07:52 AM|LINK
i have gridview bind with 1 datasource to get all data, but now i want to add 1 more dropdown which need to get the data from other table. Did anyone have idea how to do this? in VB, thanks
mm10
Contributor
6409 Points
1184 Posts
Re: how to bind dropdownlist datasource to different sql select statement?
Apr 09, 2012 09:00 AM|LINK
Add a new SqlDataSource (or similar) to select the data from the other table and then add a template field n your GridView to display the DropDownList with the data from the new DataSource control:
<asp:GridView....>
<Columns>
....
<asp:TemplateField HeaderText="dropdownlist">
<ItemTemplate>
<asp:DropDownList ID="ddl" runat="server" AppendDataBoundItems="true" DataSourceID="newDataSourceId" DataTextField="id" DataValueField="name">
</ItemTemplate>
</asp:TemplateField>
..
</Columns>
<asp:GridView>
gaikwad_anil...
Contributor
2805 Points
534 Posts
Re: how to bind dropdownlist datasource to different sql select statement?
Apr 09, 2012 09:03 AM|LINK
cehck below link
http://asp.net.bigresource.com/Dropdownlist-multiple-datasources--CmejfQU7g.html
www.thecodekey.com
Please mark as answer if useful
aoshi_kh
Member
123 Points
331 Posts
Re: how to bind dropdownlist datasource to different sql select statement?
Apr 09, 2012 09:09 AM|LINK
thanks for your suggestion, i try your way but i keep getting Could not find any attribute 'appendDataBoundItems' of element 'DropDownList' and also error when i write for new datasource??
mm10
Contributor
6409 Points
1184 Posts
Re: how to bind dropdownlist datasource to different sql select statement?
Apr 09, 2012 09:37 AM|LINK
Right, remote the AppendDataBoundItems property:
<asp:DropDownList ID="ddl" runat="server" DataSourceID="newDataSourceId" DataTextField="id" DataValueField="name">
What other error message(s) do you get?
aoshi_kh
Member
123 Points
331 Posts
Re: how to bind dropdownlist datasource to different sql select statement?
Apr 09, 2012 09:41 AM|LINK
now i try to create 2 set of return result in my stored procedure, but them i bind it to the dropdownlist, it keep prompt "DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'dytValue'. dytValue is the 2nd set of data in my stored procedure, do you know who to fix this?
mm10
Contributor
6409 Points
1184 Posts
Re: how to bind dropdownlist datasource to different sql select statement?
Apr 09, 2012 09:52 AM|LINK
Why do you return two datasets from one stored procedure instead of having two separate stored procedures? You can only bind your GridView to one DataSet.
aoshi_kh
Member
123 Points
331 Posts
Re: how to bind dropdownlist datasource to different sql select statement?
Apr 09, 2012 12:30 PM|LINK
because i need to bind 2 different result in 1 gridview, do you have any idea doing that? i have my sproc as below
from 1st return set, i will need to bind all result which with where cause, then for the 2nd return set i need bind all studName which already paid in the drop down list.
Now I already can display all value in the gridview, but i having problem to bind the data in the dropdownlist for user to select.
please help if you have idea on how to do that. Thanks in advance.
ALTER
procedure [dbo].[usp_GetStudName]
AS
SET
NOCOUNT
ON
SELECT *
FROM StudentTbl St, CourseTble Ct
Where St.courseid = Ct.courseId
SET
NOCOUNT OFF
SELECT
UserName as FullName
FROM
StudentTbl
WHERE Paid <> '0'
RETURN
mm10
Contributor
6409 Points
1184 Posts
Re: how to bind dropdownlist datasource to different sql select statement?
Apr 09, 2012 12:43 PM|LINK
I don't really understand...do you want to display the students that have not paid in the dropdownlist? In that case bind the DropDownList to a SqlDataSource:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" SelectCommand="SELECT UserName as FullName FROM StudentTbl WHERE Paid <> '0'" .../>
<asp:DropDownList ID="ddl" .... DataSourceID="SqlDataSource1" DataValueField="UserName" DataTextField="UserName" />
aoshi_kh
Member
123 Points
331 Posts
Re: how to bind dropdownlist datasource to different sql select statement?
Apr 09, 2012 12:52 PM|LINK
Sorry, i currently dont have the coding to test.. only can try again tomorrow. but the method you mention i've try this afternoon, but it seems like canot direct bind the sqlDataSource to dropdownlist in gridview, will it show error because of the gridview already bind to other datasource?