2013-08-07 38 views
0

我有一個使用存儲過程與數據庫中的數據綁定的gridview。非靜態字段,方法或屬性需要對象引用'_Default.RadioButtonList2'

下面是落後在那裏我得到上述錯誤的部分代碼:

[WebMethod] 
public static string GetList(int pageIndex){ 
.... 
..... 
cmd.Parameters.AddWithValue("@customerGroup", RadioButtonList2.SelectedValue); //Error here 
.... 
.... 
} 

我爲GridView此代碼:

<asp:RadioButtonList ID="RadioButtonList2" runat="server" AutoPostBack="True" 
         Font-Size="1em" EnableViewState="true"> 
        <asp:ListItem Value="1">Africa</asp:ListItem> 
        <asp:ListItem Value="2" >America</asp:ListItem> 
        <asp:ListItem Value="3">Europe</asp:ListItem> 
        <asp:ListItem Value="4">Asia/asp:ListItem> 
        <asp:ListItem Value="5">Australia</asp:ListItem> 
       </asp:RadioButtonList> 

我如何獲得的單選按鈕的值選擇並傳遞給存儲過程? 當我刪除行代碼時,一切正常。

回答

2

問題是您已經創建了webmethod,它無法訪問任何服務器控件。 刪除它。

如果需要,則從客戶端傳遞該函數中的RadioButtonList2.SelectedValue。

[WebMethod] 
public static string GetList(int pageIndex,string radiovalue){ 
.... 
..... 
cmd.Parameters.AddWithValue("@customerGroup", radiovalue); 
.... 
.... 
} 

希望它有效。

相關問題