Datagrid / Dataset / Relations

P

Patrick

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
 
B

Branimir Giurov

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
 
P

Patrick

Thanks, it works fine with that solution


Branimir Giurov said:
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 said:
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
 
P

Patrick

Thanks, it works fine with that solution


Branimir Giurov said:
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 said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top