如何使用带有单选按钮的AJX post方法将detailClass列表绑定到gridview
how can I bind detailClass list to gridview using AJX post method with a radio button?
我有一个带有列和单选按钮的网格,我想使用Ajax Post方法将数据绑定到它。。但当我这样做的时候,单选按钮就消失了。。我想在网格视图中显示列表,每行都有单选按钮供选择。。
$(document).ready(function () {
BindGridView();
});
function BindGridView() {
$.ajax({
type: "POST",
url: "CultureHeritage.aspx/GetData",
contentType: "application/json;charset=utf-8",
data: {},
dataType: "json",
success: function (data) {
alert(data.d); //list is here..complete table
if (data.d.length > 0) {
for (var i = 0; i < data.d.length; i++) {
$("#carServiceGridView").append("<tr><td></td> <td>" +
data.d[i].CarServiceId + "</td> <td>" +
data.d[i].CarServiceName + "</td> <td>" +
data.d[i].Address + "</td> <td>" +
data.d[i].Contact1 + "</td><td>" +
data.d[i].Contact2 + "</td><td>" +
data.d[i].MinimumPrice + "</td><td>" +
data.d[i].MaximumPrice + "</td><td>" +
data.d[i].NoOfCar + "</td><td>" +
data.d[i].CarType + "</td></tr>");
}
}
},
error: function (result) {
//alert("Error login");
}
});
}
<asp:GridView ID="carServiceGridView" runat="server" ClientIDMode="Static" AutoGenerateColumns="False" DataKeyNames="CarServiceId" Width="100%" Height="100%" AlternatingRowStyle-BackColor="WhiteSmoke">
<Columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:RadioButton ID="carServiceGridViewRadioButton" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="CarServiceId" HeaderText="Id " />
<asp:BoundField DataField="CarServiceName" HeaderText="Service " />
<asp:BoundField DataField="Address" HeaderText="Address " />
<asp:BoundField DataField="Contact1" HeaderText="Contact 1 " />
<asp:BoundField DataField="Contact2" HeaderText="Contact 2 " />
<asp:BoundField DataField="MinimumPrice" HeaderText="Minimum Price " />
<asp:BoundField DataField="MaximumPrice" HeaderText="Maximum Price " />
<asp:BoundField DataField="NoOfCar" HeaderText="No Of Car " />
<asp:BoundField DataField="CarType" HeaderText="Car Types " />
</Columns>
</asp:GridView>
当您是appending
时,需要添加radio
按钮——ajax
的success
中girdview
中的rows
。
当前添加行时,添加一个空的td
,因此不会显示单选按钮。
试试这个
$("#carServiceGridView").append("<tr><td><input type='radio' value='someValue' id='carServiceGridViewRadioButton"+i+"' onchange='RadioButtonSelectOne(this)' /></td> <td>" +
data.d[i].CarServiceId + "</td> <td>" +
data.d[i].CarServiceName + "</td> <td>" +
data.d[i].Address + "</td> <td>" +
data.d[i].Contact1 + "</td><td>" +
data.d[i].Contact2 + "</td><td>" +
data.d[i].MinimumPrice + "</td><td>" +
data.d[i].MaximumPrice + "</td><td>" +
data.d[i].NoOfCar + "</td><td>" +
data.d[i].CarType + "</td></tr>");
相关文章:
- 要求输入在数据列表中
- 从javascript创建一个列表
- 如何使用jQuery选择下拉列表的值
- 将输入字段中的文本提交到我的数据库,同时将其添加到我的列表中
- 将jsp文件下拉列表中的选定项分配给一个java变量(比如String selection)
- Javascript按钮下拉列表
- 如何使用json将对象列表从java转换为javascript
- 区分JSON中的矩阵和列表列表
- jQuery表单添加不适用于下拉列表
- 用每小时的差值填充数组/列表-从下拉列表中给定两个时间值
- 接受不在列表中的值-引导组合框
- 禁用jQuery中的下拉列表
- 从HTTPGET返回一个自定义对象列表,以便在Angular 2应用程序中使用
- 如何在javascript中迭代数字列表
- 如何在按钮中显示下拉列表中选定的元素
- 为什么HTML5拖放的目标是孩子?(可排序列表)
- 鼠标悬停事件影响列表中所有行中的按钮,而不仅仅是特定按钮
- 使用图像数组列表的simplegallary.js显示适合桌面屏幕的图像
- 如何在从多选下拉列表中选择选项值时动态生成文本框
- 如何使用带有单选按钮的AJX post方法将detailClass列表绑定到gridview