2011-05-14 98 views
1

我只是增加了一個DropDownList到我的ASP.NET網頁收到錯誤:「錯誤CS0117:‘System.Web.UI.Control’不包含定義‘的ItemIndex’

現在,當我運行,它給了我以下錯誤:

error CS0117: 'System.Web.UI.Control' does not contain a definition for 'ItemIndex'

出了什麼問題

編輯:這是我補充的部分:

<div id="AddUsers" runat="server" style="border: 1px solid skyblue; background-color: #DDEEFF;" visible="true"> 
    <table width="100%"> 
     <tr> 
      <td class="style2"> 
       <b>First Name</b><span style="color: #cc0000"> 
      *</span></td> 
      <td class="style3"> 
       <b>Middle Name</b> </td> 

      <td class="style2"> 
       <b>Last Name</b><span style="color: #cc0000"> 
      *</span></td> 
      <td style=" width: 100px;" > 
       <b>PAN No</b><span style="color: #cc0000"> 
      *</span></td> 
      <td style=" width: 100px;" > 
       <b>Financial Year</b></td> 
      <td width="13%"> 
      </td> 
     </tr> 
     <tr> 
      <td class="style2"> 
       <asp:TextBox ID="txtFirstName_1" runat="server" CssClass="fields" Width="100px" Height="18px" MaxLength="25" /> 
      </td> 
      <td class="style4"> 
       <asp:TextBox ID="txtMiddleName" runat="server" CssClass="fields" MaxLength="75" Width="100px" Height="18px" /> 
      </td> 
      <td class="style2">& 
       <asp:TextBox ID="txtLastName_1" runat="server" CssClass="fields" MaxLength="25" Width="100px" Height="18px" /> 
      </td> 
      <td style="width: 110px;font-weight: bold;color: #000000;"> 
       <asp:TextBox ID="txtPAN_NumberI_p1" runat="server" style="text-transform: uppercase" CssClass="fields" MaxLength="10" Width="100px" Height="18px" /> 
      </td> 
      <td style="width: 110px;font-weight: bold;color: #000000;"> 
       <asp:DropDownList ID="ddlChooseFY" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlChooseFY_SelectedIndexChanged"> 
        <asp:ListItem Value="-- SELECT --">-- SELECT --</asp:ListItem> 
        <asp:ListItem Value="2011">2009 - 2010</asp:ListItem> 
        <asp:ListItem Value="2010">2010 - 2011</asp:ListItem> 
       </asp:DropDownList> 
      </td> 
      <td width="13%"> 
       <asp:Button ID="imgAdd" runat="server" Text="Add User" CssClass="button" Height="22px" onclick="imgAdd_Click" Width="76px" /> 
      </td> 
      <td width="10%"> 
       <input id="Button1" type="button" class="button1" onclick="ClearUser();" style="cursor:pointer" value="Clear" /> 
      </td> 
     </tr> 
    </table> 
    <br /> 
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NOTE</b>: PAN 
    No. once entered cannot be changed. Hence, please ensure that your PAN No is 
    correct.<br />  
</div> 

編號:

Session["Year"].ToString() = ddlChooseFY.SelectedItem.Value.ToString(); 
res = Common.UserAdd(Session["UserName"].ToString(), Session["Year"].ToString(), txtPAN_NumberI_p1.Text.ToUpper()); 
+0

HTML請... – 2011-05-14 10:59:53

+0

現在的C#代碼plase – abatishchev 2011-05-14 11:05:40

回答

1
Control item = dropDownList1.Items[0]; 
item.ItemIndex; // cs0117 

ListItem item = dropDownList1.Items[0]; 
item.ItemIndex; // ok 

什麼意思,你需要澄清之前使用的類型。在投將幫助大多數情況下:

Control item; 
((ListItem)item).ItemIndex 

string year = ddlChooseFY.SelectedItem.Value; // already string, don't call ToString() 
//Session["Year"].ToString() // no!! don't do this, this makes no sense at all 
Session["Year"] = year; // do this instead 

string year = (string)Session["Year"]; // cache and cast, if you know the actual type 
// or Session["Year"] as string; if (year != null) ... 
res = Common.UserAdd(year, year, txtPAN_NumberI_p1.Text.ToUpper()); 
+0

所以是的.aspx頁面或aspx.cs頁面的問題? – meetpd 2011-05-14 11:02:58

+0

@meetpd:code-behind(* .cs) – abatishchev 2011-05-14 11:05:28

+0

Session [「Year」]。ToString()= ddlChooseFY.SelectedItem.Value.ToString(); res = Common.UserAdd(Session [「UserName」]。ToString(),Session [「Year」]。ToString(),txtPAN_NumberI_p1.Text.ToUpper()); – meetpd 2011-05-14 11:07:32

相關問題