Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

dynamically binding a field in a Gridview

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Robert Smith - 08 Mar 2008 19:41 GMT
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

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.