J
John Hoge
I have a datagrid that needs to display information from a related
table, and I have use a template column to pass the Container.DataItem
object to a method called ShowPub as follows:
<asp:TemplateColumn HeaderText="Publisher">
<ItemTemplate>
<asp:Label Runat="server" Text='<%#ShowPub(Container.DataItem)%>' />
</ItemTemplate>
</asp:TemplateColumn>
The method ShowPub did not work when I first tried it like this:
protected string ShowPub(DataRowView drv)
{
EmpDS.employeeRow theRow = (EmpDS.employeeRow)drv.Row;
return theRow.publishersRow["pub_name"].ToString();
}
Once I modified it to take an object, and then cast it to a
DataRowView, it worked fine:
protected string ShowPub(object o)
{
DataRowView drv = (DataRowView)o;
EmpDS.employeeRow theRow = (EmpDS.employeeRow)drv.Row;
return theRow.publishersRow["pub_name"].ToString();
}
If I'm sending a DataRowView object, why can't I specifiy that type in
the method signature?
table, and I have use a template column to pass the Container.DataItem
object to a method called ShowPub as follows:
<asp:TemplateColumn HeaderText="Publisher">
<ItemTemplate>
<asp:Label Runat="server" Text='<%#ShowPub(Container.DataItem)%>' />
</ItemTemplate>
</asp:TemplateColumn>
The method ShowPub did not work when I first tried it like this:
protected string ShowPub(DataRowView drv)
{
EmpDS.employeeRow theRow = (EmpDS.employeeRow)drv.Row;
return theRow.publishersRow["pub_name"].ToString();
}
Once I modified it to take an object, and then cast it to a
DataRowView, it worked fine:
protected string ShowPub(object o)
{
DataRowView drv = (DataRowView)o;
EmpDS.employeeRow theRow = (EmpDS.employeeRow)drv.Row;
return theRow.publishersRow["pub_name"].ToString();
}
If I'm sending a DataRowView object, why can't I specifiy that type in
the method signature?