>Any idea how I would go about this? Any and all suggestions appreciated.
Well, since posting I have made some progress, but I'm not sure if I'm
doing this the most sensible way. For that matter, what I'm doing
doesn't work anyway!! I will post what I have so far and would be very
grateful for any comments. Sorry it's a bit long, but it's not too hard
;-)
First I created a new class...
public class eCommVariation : IComparable {
public int avalueid;
public string varName;
public bool showVar;
public float price;
public bool specialOffer;
public float specialPrice;
public int CompareTo(object objRhs) {
eCommVariation rhs = (eCommVariation)objRhs;
return String.Compare(this.varName, rhs.varName);
}
}
and used this on postback to create an ArrayList containing the existing
values in the repeater (which is called rptNpVars), add the new value,
sort and then bind the repeater to this ArrayList...
ArrayList arrNpVars = new ArrayList();
// add the existing variations
for (int i=0; i<rptNpVars.Items.Count; i++) {
eCommVariation nPVar = new eCommVariation();
nPVar.avalueid = Convert.ToInt32(((HtmlInputHidden)rptNpVars.Items[i].FindControl("hidVarID")).Value);
nPVar.varName = ((TextBox)rptNpVars.Items[i].FindControl("txtNpVarName")).ToString();
nPVar.showVar = ((CheckBox)rptNpVars.Items[i].FindControl("chkShowNpVar")).Checked;
// next three aren't relevant for non-priced variations, set them to dummy values
nPVar.price = 0;
nPVar.specialOffer = false;
nPVar.specialPrice = 0;
arrNpVars.Add(nPVar);
}
// now add the new value
eCommVariation newNpVar = new eCommVariation();
newNpVar.avalueid = 0; // shows it's a new value
newNpVar.varName = txtNewNpVar.ToString();
newNpVar.showVar = chkShowNewNpVar.Checked;
// set the next three to anything as before
newNpVar.price = 0;
newNpVar.specialOffer = false;
newNpVar.specialPrice = 0;
arrNpVars.Add(newNpVar);
// so now we have the array of eCommVariation objects set up, sort it and bind it to the repeater
arrNpVars.Sort();
rptNpVars.DataSource = arrNpVars;
rptNpVars.DataBind();
The ItemTemplate of the repeater looks like this...
<ItemTemplate>
<tr>
<td align="center" valign="top">
<asp:CheckBox ID="chkDeleteNpVar" Text="" Checked="False" RunAt="server"/>
<input type="hidden" name="hidVarID" value='<%#DataBinder.Eval(Container.DataItem, "avalueid")%>' RunAt="Server" />
</td>
<td align="left" valign="top">
<asp:TextBox ID="txtNpVarName" Text='<%#DataBinder.Eval(Container.DataItem, "avalue")%>' Columns="20" MaxLength="20" cssClass="box"
RunAt="server" />
</td>
<td align="center" valign="top">
<asp:CheckBox ID="chkShowNpVar" Text="" Checked='<%#TrueIfY((string)DataBinder.Eval(Contai ner.DataItem, "show_avalue"))%>' RunAt="server"/>
</td>
</tr>
</ItemTemplate>
Now, I have two problems here. The first is that the line where I try to
set nPVar.avalueid for the existing item fails. Here is the line...
nPVar.avalueid = Convert.ToInt32(((HtmlInputHidden)rptNpVars.Items[i].FindControl("hidVarID")).Value);
This gives an error "Object reference not set to an instance of an
object". I tried splitting this into two lines, one to get the
HtmlInputHidden control, and one to pull out the value, but this only
showed me that the control could not be found. Any idea why when it is
obviously (to me!!) in the ItemTemplate?
I tried commenting that line out and setting the id to zero whilst I
tested the rest, and then I got this error...
DataBinder.Eval: 'PixataWebUtils.eCommVariation' does not contain a
property with the name avalueid.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.Web.HttpException: DataBinder.Eval:
'PixataWebUtils.eCommVariation' does not contain a property with the
name avalueid.
Source Error:
Line 218:<ItemTemplate>
Line 219:<tr>
Line 220:<td align="center" valign="top"><asp:CheckBox ID="chkDeleteNpVar" Text="" Checked="False" RunAt="server"/><input type="hidden"
name="hidVarID" value='<%#DataBinder.Eval(Container.DataItem, "avalueid")%>' RunAt="Server" /></td>
Line 221:<td align="left" valign="top"><asp:TextBox ID="txtNpVarName" Text='<%#DataBinder.Eval(Container.DataItem, "avalue")%>' Columns="20"
MaxLength="20" cssClass="box" RunAt="server" /></td>Line 222:<td align="center" valign="top"><asp:CheckBox ID="chkShowNpVar" Text=""
Checked='<%#TrueIfY((string)DataBinder.Eval(Contai ner.DataItem, "show_avalue"))%>' RunAt="server"/></td>
Source File: D:\WebSites\E-CommercePackage\pdap\product.aspx Line: 220
Now you can see from the code earlier that the eCommVariation class
*does* contain a property called "avalueid". I have deleted and
recompiled the DLL, but it doesn't make any difference.
I'm sure these are two stupid mistakes, but I really can't see where
they are. Any help would be greatly appreciated. TIA
--
Alan Silver
(anything added below this line is nothing to do with me)