Hi,
I would like to bind a datafield in gridvew dynamilcally because I want
to use the same grid for 2 different datasets. The column names in the
dataset are the same for both.
In dataset 1 I have a column called AgencyName,
in dataset 2 I have a column name called AdvertiserName both in the 3rd column
Can I bind the field to a particular column in the dataset
I have
<asp:TemplateField HeaderText="Agency_Name">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#
Bind("Advertiser_Name") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
Can the Bind command be manipulated to use dataset.table.column[3] etc, if
so how?
Thanks in advance
Robert
Misbah Arefin - 09 Mar 2008 02:39 GMT
you cannot specify an ordinal in the eval/bind functions
the bind method takes the name of a data field and returns a string
containing the value of that field from the current record in the data source
public static Object Eval(
Object container,
string expression
)
container:
the object reference against which the expression is evaluated. this must be
a valid object identifier in the page's specified language.
expression:
the navigation path from the container object to the public property value
to be placed in the bound control property. this must be a string of property
or field names separated by periods, such as Tables[0].DefaultView.[0].Price
you could change the column name for your dataset2 to match the column name
of dataset1 before binding to the gridview control e.g.
DataSet2.Table[0].Columns[3].ColumnName =
DataSet1.Table[0].Columns[3].ColumnName
//bind to data source
DataGrid1.Bind();
//revert the change in dataset if the columnname is needed afterwards
DataSet2.Table[0].Columns[3].ColumnName = "OrgColName";

Signature
Misbah Arefin
https://mcp.support.microsoft.com/profile/MISBAH.AREFIN
http://www.linkedin.com/in/misbaharefin
> Hi,
> I would like to bind a datafield in gridvew dynamilcally because I want
[quoted text clipped - 17 lines]
> Thanks in advance
> Robert