Hi,
I'll try to make this straightforward
I have a gridview on my aspx page:
<asp:GridView ID="ObjectList" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="ObjID" Visible="false"/>
<asp:BoundField DataField="EnglishEqu" HeaderText='<%EngTitle%>' />
<asp:TemplateField HeaderText='<%NewTitle%>'>
<ItemTemplate>
<asp:TextBox ID="NewLangEqu" runat="server" MaxLength="255"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
I need to bind this list to a collection which is built up in my code behind page:
code behind:
int iVal = int.Parse(ListLanguageList.SelectedValue);
DataSet ds = DatabaseMethods.GetLanguageObjectSet(iVal);
LanguageGridCollection col = new LanguageGridCollection();
foreach (DataRow dr in ds.Tables[0].Rows)
{
LanguageGridClass lan = new LanguageGridClass();
lan.ObjID = dr[0].ToString();
lan.NewLabel = dr[1].ToString();
//loop through each property in the main resource file
foreach (PropertyInfo info in (typeof(Resources.ClaimTracking)).GetProperties())
{
//if the property is a string then....
if (info.PropertyType == typeof(string))
{
if (info.Name == lan.ObjID)
{
lan.EnglishLabel = info.GetValue(info, null).ToString();
}
col.Add(lan);
}
}
}
//we now have a list of objIDs and english labels and new labels (if a new label exists)
ObjectList.DataSource = col;
ObjectList.DataBind();
custom class and collection codecollection code
public class LanguageGridClass
{
public LanguageGridClass() { }
//the names of the items in the RESX files are unique, ergo each ObjID will be unique
private string objID;
public string ObjID
{
get
{
return objID;
}
set
{
objID = value;
}
}
private string englishLabel;
public string EnglishLabel
{
get
{
return englishLabel;
}
set
{
englishLabel = value;
}
}
private string newLabel;
public string NewLabel
{
get
{
return newLabel;
}
set
{
newLabel = value;
}
}
}
public class LanguageGridCollection : IColumns<LanguageGridClass>
{
//member variable - used to store the actual list
private List<LanguageGridClass> Items = new List<LanguageGridClass>();
//override, return the list
public List<LanguageGridClass> ListOfColumns()
{
return Items;
}
//add to the list
public void Add(LanguageGridClass item)
{
Items.Add(item);
}
//remove from the list
public void Remove(LanguageGridClass item)
{
Items.Remove(item);
}
//clear all columns from list
public void Clear()
{
Items.Clear();
}
public LanguageGridClass this[int index]
{
get
{
return ((LanguageGridClass)(this.Items[index]));
}
set
{
this.Items[index] = value;
}
}
}
The error I get is the one in the subject line and it occurs on "ObjectList.DataSource = col;" line
I am not really sure I fully understand the error nor do I know how to go about fixing this.
Anyone with any ideas???
many thanks