If it's in another table in the dataset, you might be better off copying the column into the
primary table (depends I guess); anyway, here's some code that demos calling a separate method to
fillin a column with whatever you want.
Scott
<%@ Import Namespace="System.Data" %>
<%@ Page language="c#" AutoEventWireup="false" %>
<html>
<head>
<title>DGBind</title>
<script language="C#" runat="server">
protected override void OnLoad(EventArgs e)
{
this.DG.DataSource = MyFakeDataSet;
this.DG.DataMember = "Table1";
this.DG.DataBind();
}
private DataSet m_ds;
private DataSet MyFakeDataSet {
get {
if (m_ds != null) {
return m_ds;
}
m_ds = new DataSet();
DataTable t = new DataTable("Table1");
t.Columns.Add("Column1");
m_ds.Tables.Add(t);
for (int i = 0; i < 10; i++) {
DataRow r = m_ds.Tables[0].NewRow();
r["Column1"] = i.ToString();
m_ds.Tables[0].Rows.Add(r);
}
return m_ds;
}
}
protected string GetColumn2(string x) {
return "Get the row in a second table where Column1 = " + x;
}
</script>
</head>
<body>
<form id="Form1" method="post" runat="server">
<asp:datagrid id="DG" runat="server" autogeneratecolumns="False">
<columns>
<asp:boundcolumn datafield="Column1" headertext="Column1"></asp:boundcolumn>
<asp:templatecolumn headertext="Column2">
<itemtemplate><asp:label runat="server" text='<%# GetColumn2(DataBinder.Eval(Container,
"DataItem.Column1").ToString()) %>'></asp:label>
</itemtemplate>
</asp:templatecolumn>
</columns>
</asp:datagrid>
</form>
</body>
</html>
Paulo said:
Hey, thanks for the help. I've got my lookup table in my dataset and related to the primary table.
Can you give an example of how the event handler would look like?
I was trying to use a custom data binding expression but I couldn't figure out a way to get the
data I need.