473,320 Members | 1,802 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

GridView DataBind() Not Working

I have a GridView as a child control in a custom composite control which is stubornly refusing to databind at design time. I'm
convinced I must be missing something about how the databinding process works differently at design time.

Here is the code that constructs the GridView in CreateChildControls():

gridSearch = new GridView();

gridSearch.AutoGenerateColumns = true;

CommandField cmdField = new CommandField();
cmdField.ShowSelectButton = false;
cmdField.SelectText = "select";
gridSearch.Columns.Add(cmdField);

FieldInfoCollection fieldColl = DesignMode ? DummyData.Fields : SearchFields;

for( int idx = 0; idx < fieldColl.Count; idx++ )
{
BoundField curField = new BoundField();

curField.HeaderText = fieldColl[idx].Friendly;
curField.DataField = fieldColl[idx].FieldName;
curField.ReadOnly = true;
curField.ShowHeader = true;
curField.Visible = true;

gridSearch.Columns.Add(curField);
}

At design time DummyData.Fields is composed of five "rows" of data in a List<>, where each row is a simple object:

public class DummyDataItem
{
private int row = 0;

public DummyDataItem( int row )
{
this.row = row;
}

protected string FieldValue( int row, int col )
{
return String.Format("Field{0}_Row{1}", col, row);
}

public string Field1
{
get { return FieldValue(row, 1); }
}

public string Field2
{
get { return FieldValue(row, 2); }
}

public string Field3
{
get { return FieldValue(row, 3); }
}
}

DummyData.Fields simply returns a list that has FieldNames of Field1, Field2 and Field3, corresponding to the properties in
DummyDataItem.

Later on the composite control that contains the GridView has its DataSource property set to that List<of DummyDataItems, and then
the following code gets called in an event handler:

gridSearch.DataSource = DataSource;
gridSearch.DataBind();

No rows are created. No exceptions are thrown. I can walk over the code in the debugger, so I know the event handler is being
triggered. I verified that the gridSearch, at the point of the DataBind() call, has columns with DataField properties equal to
Field1, Field2 and Field3.

Yet it doesn't work. How could this be any simpler? Do GridViews not work with List<of objects exposing public string properties?

I would appreciate some advice or suggestions.

- Mark
Feb 17 '07 #1
1 4104
Hello Mark,

Regarding on this issue, I have replied you in your another duplicated
thread within the
"microsoft.public.dotnet.framework.aspnet.building controls" newsgroup.
Please feel free to continue discuss there if you feel convenient.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 19 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: | last post by:
Hello, I have a GridView in my ASP.NET 2.0 application that performs the paging feature perfect when I have it bound to a data source. But now I have it bound to a dataset and the paging...
5
by: Dick | last post by:
I have a GridView bound to an ObjectDataSource. I have a Button that calls GridView.DataBind. I want the row that is selected before the DataBind to still be selected afterwards. This happens...
2
by: needin4mation | last post by:
In a GridView, take for example a delete button. When I click the delete button in my GridView the GridView row is deleted and the GridView rebinds and refreshes the records to show accurately. ...
1
by: mitchman10 | last post by:
My Time table has TimeID,Employee,PayPeriod,ChargeCodeID,Hours My Chargecode table has ChargecodeID,c_Text I need an Editable datagrid that will show the TimeID,Employee,PayPeriod,C_Text in a...
5
by: Randy Smith | last post by:
Hi ALL, I wonder if anyone has been using n-tier to bind to a GridView control by using the ObjectDataSource. This is our first OOP web application, and we have no tables. Right now we are...
8
by: =?Utf-8?B?TWlrZSBSYW5k?= | last post by:
I am trying to get a list of files from a specified directory using the System.IO namespace classes, and then use that list as the datasource for a GridView. I have been able to do this...
4
by: GaryDean | last post by:
I have an objectdatasource reading a dataset and I have a gridview using that objectdatasource (at design time). It binds fine but I need to clear it. myGridView.DataSource = null:...
3
by: Nathan Sokalski | last post by:
I have a GridView control with three columns, all BoundField columns. They all have a HeaderText and DataField property set, and the third one has a DataFormatString property as well. When I run my...
3
by: Peter | last post by:
I have a GridView which is populated by List<ofObjects> Does anyone have example of how to sort the columns of this GridView? I have found examples without DataSourceControl but these use...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.