Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: aspx to codebehind value becomes null?


Message #1 by John Mandia <John.Mandia@X...> on Tue, 4 Dec 2001 09:29:37 -0000
Hi All,



I have a column which uses the following:



<EDITITEMTEMPLATE>



<asp:DropDownList runat="server" SelectedIndex='<%# GetItemIndex(DataBinder.Eval(Container.DataItem,
"ItemDeXcription").ToString()) %>'

id="edit_ItemDescription">



<asp:ListItem>Computer</asp:ListItem>

<asp:ListItem>Monitor</asp:ListItem>

<asp:ListItem>Printer</asp:ListItem>



</asp:DropDownList>



<asp:Label id="labeltest" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "ItemDeXcription")
%>'></asp:Label></EDITITEMTEMPLATE>I added the label to check the value coming out which in this case isMonitor.I
have a code behind file with the following:private void Page_Load(object sender, System.EventArgs e)  {   // Put user code to
initialize the page here   ItemIndex = new Hashtable();   ItemIndex["Computer"] = 0;   ItemIndex["Monitor"] = 1;  
ItemIndex["Printer"] = 2;  }public int GetItemIndex(String itemName)  {   if (ItemIndex[itemName] != null)    return
(int)ItemIndex[itemName];   else    return 0;  }For Some reason it seems to be passing null as it always returns 0.  Whichis
Computer.If I hard code it in:<asp:DropDownList runat="server" SelectedIndex='<%# GetItemIndex("Monitor")%>'
id="edit_ItemDescription">It works fine.  This works in the quickstarts but doesn't in mine (Onlymain difference being mine has a
code behind page).Can someone point out where i am slipping up?Thanks,John





This e-mail including any attachments is confidential and may be 

legally privileged. If you have received it in error please advise the

sender immediately by return email and then delete it from your 

system. 

The unauthorised use, distribution, copying or alteration of this 

email is strictly forbidden. If you need assistance please contact the

help desk on (+44)(0)870 8704820


  Return to Index