Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > how to connect 2 labels in gridview to two different sqldatasources?

Reply
Thread Tools

how to connect 2 labels in gridview to two different sqldatasources?

 
 
Luc
Guest
Posts: n/a
 
      09-22-2009
Hi,

the gridview is connected to sqldatasource1.
is it possible to connect one label into that gridview to one field in
sqldatasource1 and another label in the same gridview to another
sqldatasource2?
I did this, but i don't know how to link label 'fromtable2' to 'fieldtb2' in
sqldatasource2.
I couldn't find propety "datasourceID" for label (or textbox). Dropdownlist
has that property.

Thanks for help
Luc

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:myconn %>"
SelectCommand="SELECT fieldtb1 FROM [table1]
></asp:SqlDataSource>


<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:myconn %>"
SelectCommand="SELECT fieldtb2 FROM [table2] ></asp:SqlDataSource>
</asp:SqlDataSource>

<asp:GridView ID="GridView1" runat="server"
DataSourceID="SqlDataSource1" DataKeyNames="field1" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label id="fromtable1" runat="server" Text='<%#
eval("fieldtb1") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

<asp:TemplateField>
<ItemTemplate>
<asp:Label id="fromtable2" runat="server" Text='<%#
eval("fieldtb2") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</gridview>


 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      09-22-2009
you should do a sql join and have only one datasource.

-- bruce (sqlwork.com)

Luc wrote:
> Hi,
>
> the gridview is connected to sqldatasource1.
> is it possible to connect one label into that gridview to one field in
> sqldatasource1 and another label in the same gridview to another
> sqldatasource2?
> I did this, but i don't know how to link label 'fromtable2' to 'fieldtb2' in
> sqldatasource2.
> I couldn't find propety "datasourceID" for label (or textbox). Dropdownlist
> has that property.
>
> Thanks for help
> Luc
>
> <asp:SqlDataSource ID="SqlDataSource1" runat="server"
> ConnectionString="<%$ ConnectionStrings:myconn %>"
> SelectCommand="SELECT fieldtb1 FROM [table1]
> ></asp:SqlDataSource>

>
> <asp:SqlDataSource ID="SqlDataSource2" runat="server"
> ConnectionString="<%$ ConnectionStrings:myconn %>"
> SelectCommand="SELECT fieldtb2 FROM [table2] ></asp:SqlDataSource>
> </asp:SqlDataSource>
>
> <asp:GridView ID="GridView1" runat="server"
> DataSourceID="SqlDataSource1" DataKeyNames="field1" >
> <Columns>
> <asp:TemplateField>
> <ItemTemplate>
> <asp:Label id="fromtable1" runat="server" Text='<%#
> eval("fieldtb1") %>'></asp:Label>
> </ItemTemplate>
> </asp:TemplateField>
>
> <asp:TemplateField>
> <ItemTemplate>
> <asp:Label id="fromtable2" runat="server" Text='<%#
> eval("fieldtb2") %>'></asp:Label>
> </ItemTemplate>
> </asp:TemplateField>
> </Columns>
> </gridview>
>
>

 
Reply With Quote
 
 
 
 
Luc
Guest
Posts: n/a
 
      09-22-2009
thanks for replying.

But what if both tables haven't anything common?

"bruce barker" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> you should do a sql join and have only one datasource.
>
> -- bruce (sqlwork.com)
>
> Luc wrote:
>> Hi,
>>
>> the gridview is connected to sqldatasource1.
>> is it possible to connect one label into that gridview to one field in
>> sqldatasource1 and another label in the same gridview to another
>> sqldatasource2?
>> I did this, but i don't know how to link label 'fromtable2' to 'fieldtb2'
>> in sqldatasource2.
>> I couldn't find propety "datasourceID" for label (or textbox).
>> Dropdownlist has that property.
>>
>> Thanks for help
>> Luc
>>
>> <asp:SqlDataSource ID="SqlDataSource1" runat="server"
>> ConnectionString="<%$ ConnectionStrings:myconn %>"
>> SelectCommand="SELECT fieldtb1 FROM [table1]
>> ></asp:SqlDataSource>

>>
>> <asp:SqlDataSource ID="SqlDataSource2" runat="server"
>> ConnectionString="<%$ ConnectionStrings:myconn %>"
>> SelectCommand="SELECT fieldtb2 FROM [table2] ></asp:SqlDataSource>
>> </asp:SqlDataSource>
>>
>> <asp:GridView ID="GridView1" runat="server"
>> DataSourceID="SqlDataSource1" DataKeyNames="field1" >
>> <Columns>
>> <asp:TemplateField>
>> <ItemTemplate>
>> <asp:Label id="fromtable1" runat="server" Text='<%#
>> eval("fieldtb1") %>'></asp:Label>
>> </ItemTemplate>
>> </asp:TemplateField>
>>
>> <asp:TemplateField>
>> <ItemTemplate>
>> <asp:Label id="fromtable2" runat="server" Text='<%#
>> eval("fieldtb2") %>'></asp:Label>
>> </ItemTemplate>
>> </asp:TemplateField>
>> </Columns>
>> </gridview>



 
Reply With Quote
 
Gregory A. Beamer
Guest
Posts: n/a
 
      09-22-2009
"Luc" <dfgdf@sdfsd> wrote in news:u$(E-Mail Removed):

> thanks for replying.
>
> But what if both tables haven't anything common?


They have to have something unless you are arbitrarily filling the textbox
with random junk. there has to be some reason you are choosing the data you
are choosing. That reason is how they are linked, physically or just
logically. Then again, I have seen instances where it seemed like the
controls were just filled with random junk, so I could be wrong.

As for filling. If you cannot join tables, then use the row binding event
handler to bind the "junk" in the textbox.

Peace and Grace,

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

My vacation and childhood cancer awareness site:
http://www.crazycancertour.com

*******************************************
| Think outside the box! |
*******************************************
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
"pointlabel"-like function for Python: distribute text labels on a2-d scatter plot to avoid overlapping labels C Barrington-Leigh Python 1 09-12-2010 09:58 PM
How to connect two different location servers? GS Cisco 8 07-22-2008 02:32 PM
one laptop, two completely different networks, how to connect to e =?Utf-8?B?RWR3YXJkIExldGVuZHJl?= Wireless Networking 3 10-18-2007 08:47 AM
use two different versions of DB2 connect with Lindies Computer Support 0 08-05-2004 01:40 PM



Advertisments