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

Discussion in 'ASP .Net' started by Luc, Sep 22, 2009.

  1. Luc

    Luc Guest

    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>
     
    Luc, Sep 22, 2009
    #1
    1. Advertising

  2. Luc

    bruce barker Guest

    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>
    >
    >
     
    bruce barker, Sep 22, 2009
    #2
    1. Advertising

  3. Luc

    Luc Guest

    thanks for replying.

    But what if both tables haven't anything common?

    "bruce barker" <> schreef in bericht
    news:...
    > 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>
     
    Luc, Sep 22, 2009
    #3
  4. "Luc" <dfgdf@sdfsd> wrote in news:u$:

    > 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! |
    *******************************************
     
    Gregory A. Beamer, Sep 22, 2009
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael Kellogg
    Replies:
    0
    Views:
    890
    Michael Kellogg
    Apr 6, 2006
  2. =?Utf-8?B?TXIuIE11cmFkIEphbWFs?=

    GridView & Labels ?

    =?Utf-8?B?TXIuIE11cmFkIEphbWFs?=, Jun 7, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    511
    Jan Hyde
    Jun 7, 2006
  3. Replies:
    1
    Views:
    242
    Dennis Lee Bieber
    Jun 9, 2005
  4. Keithb
    Replies:
    0
    Views:
    2,922
    Keithb
    Nov 4, 2006
  5. Mr. Murad Jamal

    GridView & Labels ?

    Mr. Murad Jamal, Jun 7, 2006, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    122
    Jan Hyde
    Jun 7, 2006
Loading...

Share This Page