Datagrid / Dataset / Relations

Discussion in 'ASP .Net Datagrid Control' started by Patrick, Jan 26, 2004.

  1. Patrick

    Patrick Guest

    Hi , I'm sure that I'm not the first one with that question. I have two
    tables (both in the Dataset), where one is

    parent_table
    id:
    sname:

    child_table:
    id
    iparent_id
    schildname

    now i load into the datatable the child_table as Datamember. So now I can
    edit, Insert and delete these Items. now what I want to do is to display
    instead of the parent_id the parent_table.sname. How can i do this? and
    second step is, when editing that row, that for the parent will be displayed
    a dropdown-list... anyone an idea/url to solve these problems?

    thanks
    patrick
     
    Patrick, Jan 26, 2004
    #1
    1. Advertising

  2. Hi Patrick,
    you can do a Select() on the parent table, while you bind the rows to the
    datasource. Your aspx page should look like this:

    <asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 24px; POSITION:
    absolute; TOP: 19px" runat="server">
    <Columns>
    <asp:TemplateColumn>
    <%# getParentValue(DataBinder.Eval(Container.DataItem,
    "parent_id").ToString() ) ) %>
    </asp:TemplateColumn>
    </Columns>
    </asp:DataGrid>

    then into the codebehind:

    protected string getParentValue(string parentID)
    {
    DataRow[] result =
    datasource.Tables["parent_table"].Select(string.Format("parent_id ='{0}'",
    parentID));
    if ( result!=null && result.Length > 0 )
    return result[0]["sname"].ToString();
    return "";
    }

    good luck :)
    Branimir

    --
    Branimir Giurov
    MCSD.NET, MCDBA
    eAgility LLC
    "Patrick" <> wrote in message
    news:...
    > Hi , I'm sure that I'm not the first one with that question. I have two
    > tables (both in the Dataset), where one is
    >
    > parent_table
    > id:
    > sname:
    >
    > child_table:
    > id
    > iparent_id
    > schildname
    >
    > now i load into the datatable the child_table as Datamember. So now I can
    > edit, Insert and delete these Items. now what I want to do is to display
    > instead of the the parent_table.sname. How can i do this? and
    > second step is, when editing that row, that for the parent will be

    displayed
    > a dropdown-list... anyone an idea/url to solve these problems?
    >
    > thanks
    > patrick
    >
    >
     
    Branimir Giurov, Jan 26, 2004
    #2
    1. Advertising

  3. Patrick

    Patrick Guest

    Thanks, it works fine with that solution


    "Branimir Giurov" <> schrieb im Newsbeitrag
    news:uIM$...
    > Hi Patrick,
    > you can do a Select() on the parent table, while you bind the rows to the
    > datasource. Your aspx page should look like this:
    >
    > <asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 24px; POSITION:
    > absolute; TOP: 19px" runat="server">
    > <Columns>
    > <asp:TemplateColumn>
    > <%# getParentValue(DataBinder.Eval(Container.DataItem,
    > "parent_id").ToString() ) ) %>
    > </asp:TemplateColumn>
    > </Columns>
    > </asp:DataGrid>
    >
    > then into the codebehind:
    >
    > protected string getParentValue(string parentID)
    > {
    > DataRow[] result =
    > datasource.Tables["parent_table"].Select(string.Format("parent_id ='{0}'",
    > parentID));
    > if ( result!=null && result.Length > 0 )
    > return result[0]["sname"].ToString();
    > return "";
    > }
    >
    > good luck :)
    > Branimir
    >
    > --
    > Branimir Giurov
    > MCSD.NET, MCDBA
    > eAgility LLC
    > "Patrick" <> wrote in message
    > news:...
    > > Hi , I'm sure that I'm not the first one with that question. I have two
    > > tables (both in the Dataset), where one is
    > >
    > > parent_table
    > > id:
    > > sname:
    > >
    > > child_table:
    > > id
    > > iparent_id
    > > schildname
    > >
    > > now i load into the datatable the child_table as Datamember. So now I

    can
    > > edit, Insert and delete these Items. now what I want to do is to display
    > > instead of the the parent_table.sname. How can i do this? and
    > > second step is, when editing that row, that for the parent will be

    > displayed
    > > a dropdown-list... anyone an idea/url to solve these problems?
    > >
    > > thanks
    > > patrick
    > >
    > >

    >
    >
     
    Patrick, Jan 27, 2004
    #3
  4. Patrick

    Patrick Guest

    Thanks, it works fine with that solution


    "Branimir Giurov" <> schrieb im Newsbeitrag
    news:uIM$...
    > Hi Patrick,
    > you can do a Select() on the parent table, while you bind the rows to the
    > datasource. Your aspx page should look like this:
    >
    > <asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 24px; POSITION:
    > absolute; TOP: 19px" runat="server">
    > <Columns>
    > <asp:TemplateColumn>
    > <%# getParentValue(DataBinder.Eval(Container.DataItem,
    > "parent_id").ToString() ) ) %>
    > </asp:TemplateColumn>
    > </Columns>
    > </asp:DataGrid>
    >
    > then into the codebehind:
    >
    > protected string getParentValue(string parentID)
    > {
    > DataRow[] result =
    > datasource.Tables["parent_table"].Select(string.Format("parent_id ='{0}'",
    > parentID));
    > if ( result!=null && result.Length > 0 )
    > return result[0]["sname"].ToString();
    > return "";
    > }
    >
    > good luck :)
    > Branimir
    >
    > --
    > Branimir Giurov
    > MCSD.NET, MCDBA
    > eAgility LLC
    > "Patrick" <> wrote in message
    > news:...
    > > Hi , I'm sure that I'm not the first one with that question. I have two
    > > tables (both in the Dataset), where one is
    > >
    > > parent_table
    > > id:
    > > sname:
    > >
    > > child_table:
    > > id
    > > iparent_id
    > > schildname
    > >
    > > now i load into the datatable the child_table as Datamember. So now I

    can
    > > edit, Insert and delete these Items. now what I want to do is to display
    > > instead of the the parent_table.sname. How can i do this? and
    > > second step is, when editing that row, that for the parent will be

    > displayed
    > > a dropdown-list... anyone an idea/url to solve these problems?
    > >
    > > thanks
    > > patrick
    > >
    > >

    >
    >
     
    Patrick, Jan 27, 2004
    #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. Nicolas STAMPF
    Replies:
    0
    Views:
    407
    Nicolas STAMPF
    May 4, 2004
  2. Joe Van Meer

    data relations and datasets inquiry

    Joe Van Meer, May 5, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    433
    Joe Van Meer
    May 5, 2004
  3. =?Utf-8?B?RGF2ZQ==?=

    Dataset relations and nested repeaters?

    =?Utf-8?B?RGF2ZQ==?=, Apr 15, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    465
    =?Utf-8?B?RGF2ZQ==?=
    Apr 15, 2006
  4. MRW

    Relations in Dataset

    MRW, Dec 2, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    325
  5. ree32

    Datatable Relations and Datagrid

    ree32, Dec 17, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    122
    R. Thomas, aka Xtreme.Net
    Dec 18, 2004
Loading...

Share This Page