我想从Grid中选择一条记录,当我选择一个记录时,它会将我重定向到一个详细信息表格,它会在Gridview.SelectedValue中给我一些沉闷的值。 “> 这是我的C#代码如果你问我可以提供更多代码。
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow row = GridView1.SelectedRow;
Label lbl = row.FindControl("lblJobCard") as Label;
ViewState["JobCardCode"] = lbl.Text;
string lead = GridView1.SelectedValue.ToString();
Response.Redirect("~/Modules/Service/Forms/JobCardNew.aspx?JobCardCode=" + GridView1.SelectedValue);
}
我添加了一些Jquery代码用于分页和在网格中搜索。
function GetCustomers(pageIndex) {
$.ajax({
type: "POST",
url: "JC.aspx/GetCustomers",
data: '{searchTerm: "' + SearchTerm() + '", pageIndex: ' + pageIndex + '}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(response.d);
},
error: function (response) {
alert(response.d);
}
});
}
这是我的Gridview Html代码
<asp:GridView ID="GridView1" Width="100%" runat="server" AutoGenerateColumns="False" DataKeyNames="JobCardCode"
AllowPaging="true" PageSize="5" OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
OnRowCreated="GridView1_RowCreated" DataSourceID = "SqlDataSource1"> <%----%>
<Columns>
<%--<asp:BoundField DataField="JobCardCode" HeaderText="JOB CARD" SortExpression="JobCardCode" ></asp:BoundField>\--%>
<asp:TemplateField HeaderText="Job Card" >
<ItemTemplate>
<asp:Label ID="lblJobCard" runat="server" Text='<%# Bind("JobCardCode") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="UserName" HeaderText="Name" SortExpression="UserName"></asp:BoundField>
<asp:BoundField DataField="RegNo" HeaderText="Registration #" SortExpression="RegNo"></asp:BoundField>
<asp:BoundField DataField="EngineNo" HeaderText="Engine #" SortExpression="EngineNo"></asp:BoundField>
<asp:BoundField DataField="ChassisNo" HeaderText="Chassis #" SortExpression="ChassisNo"></asp:BoundField>
<asp:CommandField ShowSelectButton="true" HeaderText="Edit" ></asp:CommandField>
</Columns>
</asp:GridView>