C# 在asp.net中,我可以将哪个对象传递到JSON?

C# 在asp.net中,我可以将哪个对象传递到JSON?,c#,jquery,asp.net,json,listbox,C#,Jquery,Asp.net,Json,Listbox,我已经创建了一个列表框。左侧列表框包含列表项,右侧列表框在服务器端没有任何内容 <div class="row" style="padding-top:10px;"> <div class="col-lg-3"> <asp:ListBox ID="lstLeft" class="form-control" runat="server" SelectionMode="Multiple" Height="220px"> &l

我已经创建了一个列表框。左侧列表框包含列表项,右侧列表框在服务器端没有任何内容

<div class="row" style="padding-top:10px;">
    <div class="col-lg-3">
        <asp:ListBox ID="lstLeft" class="form-control" runat="server" SelectionMode="Multiple" Height="220px">
        <asp:ListItem Value="transactions.storeid as StoreID">StoreID</asp:ListItem>
        <asp:ListItem Value="YEAR(transactions.Time) Year">Year</asp:ListItem>
        <asp:ListItem Value="MONTH(transactions.Time) Month">Month</asp:ListItem>
        <asp:ListItem Value="transactionsEntry.TransactionNumber">TransactionNumber</asp:ListItem>
        <asp:ListItem Value="transactionsEntry.Quantity">Quantity</asp:ListItem>
        <asp:ListItem Value="items.ItemLookupCode">ItemLookupCode</asp:ListItem>
        <asp:ListItem Value="CONVERT(varchar, CAST(transactionsEntry.Price AS money), 1)*transactionsEntry.Quantity ExtendedPrice">ExtendedPrice</asp:ListItem>
        <asp:ListItem Value="departments.Name as DepartmentName">DepartmentName</asp:ListItem>
        <asp:ListItem Value="categories.Name as CategoryName">CategoryName</asp:ListItem>
        <asp:ListItem Value="items.SubDescription1">SubDescription1</asp:ListItem>
        <asp:ListItem Value="suppliers.SupplierName">SupplierName</asp:ListItem>
        <asp:ListItem Value="suppliers.Code">Code</asp:ListItem>
        </asp:ListBox>
    </div>
    <div class="col-lg-1">
        <input type="button" id="left" value="<<" />
        <input type="button" id="right" value=">>" />
    </div>
        <div class="col-lg-3">
        <asp:ListBox ID="lstRight" runat="server" SelectionMode="Multiple" Width="100%" Height="220"></asp:ListBox>
    </div>
 </div>
当我尝试这个
alert(“Values=“+Values”)我没有定义。那么我应该在JSON中传递哪个变量呢


谢谢

使用下面的代码获取Listbox的值和文本

//Define javascript array

var arr = new Array;

$("#lstRight > option").each(function () {
       arr.push({ "Text" : $(this).text() , "Value" : $(this).val() });
});

//convert this array into json using JSON.stringify function

JSON.stringify(arr);

在浏览器中呈现时,还要检查asp.net Listbox控件的客户端id。

使用以下代码获取Listbox的值和文本

//Define javascript array

var arr = new Array;

$("#lstRight > option").each(function () {
       arr.push({ "Text" : $(this).text() , "Value" : $(this).val() });
});

//convert this array into json using JSON.stringify function

JSON.stringify(arr);

在浏览器中呈现时,还要检查asp.net列表框控件的客户端id。

我想您不明白我的问题。我已经得到了值和文本。我想将所有文本和值存储在一个数组中,如(键、值)。然后我想将该数组传递给json,并将这些键和值添加到服务器端右侧的列表框项中。明白吗?我想你不明白我的问题。我已经得到了值和文本。我想将所有文本和值存储在一个数组中,如(键、值)。然后我想将该数组传递给json,并将这些键和值添加到服务器端右侧的列表框项中。明白吗?@Div仍然是相同的
未定义的
<代码>变量选项=$(“#lstRight选项”);var values=$.map(选项,函数(选项){//alert(“Text=“+option.Text+”Value=“+option.Value”);alert(“values=“+JSON.stringify(values));})
@Div仍然相同,但未定义
<代码>变量选项=$(“#lstRight选项”);var values=$.map(选项,函数(选项){//alert(“Text=“+option.Text+”Value=“+option.Value”);alert(“values=“+JSON.stringify(values));})
//Define javascript array

var arr = new Array;

$("#lstRight > option").each(function () {
       arr.push({ "Text" : $(this).text() , "Value" : $(this).val() });
});

//convert this array into json using JSON.stringify function

JSON.stringify(arr);