Last post Nov 19, 2020 12:48 AM by shsu
Nov 17, 2020 05:45 AM|shsu|LINK
I have a Repeater which have a table. Repeater is connected to Data source 1
But one row of the table (middle row) need to show the value from datasource2 (Dtaasource1 & Datasource 2 are from unlinked tables).
How can I make it possible. Is it possible? Appreciate the help
Nov 18, 2020 06:11 AM|Sean Fang|LINK
A repeater cannot be assigned with two different data sources.
I presume that you want to bind columns with the same name from two unlinked tables.
There is a workaround that you could use 'UNION' to
concatenates result sets from two queries so that you just need one data source for data binding.
More details, you could refer to below codes.
<form id="form1" runat="server">
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
<asp:Label ID="label1" runat="server" Text='<%#Eval("ID") %>'></asp:Label>
<asp:Label ID="label2" runat="server" Text='<%#Eval("Name") %>'></asp:Label></td>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
SelectCommand="SELECT ID, Name FROM CarImgTbl UNION ALL SELECT ID, Name FROM city_table"></asp:SqlDataSource>
If you do have other conditions that we need to consider, feel free to let me know.
Nov 18, 2020 09:34 AM|shsu|LINK
SELECT RNUMBER, DESCRIPTION FROM st.HEADERS_ALL a, st.DETAILS_ALL b WHERE a.initem_id = b.initem_id and RNUMBER = '005432'
above is the current working query.
I want to UNION ALL below statement
Showing error when I did that.
Nov 18, 2020 05:35 PM|KathyW|LINK
Always tell us the error.
But I assume it's because UNION and UNION ALL require
You can solve the first problem by returning a dummy value of the correct type for the missing columns.
SELECT RNUMBER, DESCRIPTION FROM st.HEADERS_ALL
Add two dummy columns that return NULL:
SELECT RNUMBER, DESCRIPTION, NULL, NULL FROM st.HEADERS_ALL Since the column names returned will be based on the first Select, you may want to alias the dummy columns if that SELECT is first.:SELECT RNUMBER, DESCRIPTION, NULL AS BU3, NULL AS BU4 FROM st.HEADERS_ALL
If you have the second case you'd have to return dummy values in both Selects, lining up the columns to the correct type.
You'll have an interesting time in your Repeater EVALs: all columns will be returned for all rows (under the column name in the first SELECT), and you'll need to parse things in your EVAL's to display the correct ones.
Nov 19, 2020 12:48 AM|shsu|LINK
st.RP_BU is an unlinked table with different columns and datatypes.
Hence I used CROSS JOIN. It works well.
Thanks for the suggestions.