Javascript查询字符串到c#
我正在尝试从devexpress aspxGridview中的FocusedRow获取KeyField值 到目前为止,我有以下代码Javascript查询字符串到c#,c#,javascript,asp.net,query-string,client-side,C#,Javascript,Asp.net,Query String,Client Side,我正在尝试从devexpress aspxGridview中的FocusedRow获取KeyField值 到目前为止,我有以下代码 网格视图 <dx:ASPxGridView ID="ClientenSummary" runat="server" Width="700px" OnSelectionChanged="ClientenSummary_SelectionChanged" EnableCallBacks="False"> &
- 网格视图
<dx:ASPxGridView ID="ClientenSummary" runat="server" Width="700px" OnSelectionChanged="ClientenSummary_SelectionChanged" EnableCallBacks="False"> <ClientSideEvents FocusedRowChanged="function(s, e)
我不明白的是,为什么这个问题没有解决。在对互联网进行了一些调查之后,我找不到一个像样的解决方案,所以我在这里问这个问题。希望有人能帮助你好吧,首先,你的网格设置中没有
AllowFocusedRow=“true”
。这将导致它忽略FocusRowChanged的任何客户端事件
其次,您需要告诉控件是要在服务器上还是在客户端上处理焦点行更改事件。我会推荐客户,并在下面发布一些代码。(DevExpress文档:)
第三,您有ProcessSelectionChangedOnServer=“True”
,它将为您的ClientenSummary\u SelectionChanged事件触发代码。但是你没有发布这段代码,老实说,除非这是服务于你没有发布的特定功能,否则你不需要它来满足你的要求
最后,我建议设置网格的客户机实例名和键字段名。在我的java代码示例中,我使用“grid”和“ClassNR”
爪哇:
函数OnGridFocusedRowChanged(){
grid.GetRowValues(grid.GetFocusedRowIndex(),'ClassNR',OnGetRowValues);
}
函数OnGetRowValues(ClassNR){
window.location.href=“../main.aspx?FocusedRowKeyField=“+ClassNR;
}
网格:
设置:
<SettingsBehavior AllowSelectByRowClick="True" AllowSelectSingleRowOnly="True" ProcessFocusedRowChangedOnServer="false" AllowFocusedRow="true" />
客户端事件:
<ClientSideEvents FocusedRowChanged="function(s,e) { OnGridFocusedRowChanged(); }" />
下一位只是测试值,随意更改。
C#:
受保护的无效页面加载(对象发送方,事件参数e)
{
Page.ClientScript.RegisterStartupScript(this.GetType(),“myScript”,“警报”(+Request.Params[“FocusedRowKeyField”]+”);
}
这是我为你的问题设置的测试应用程序。当焦点行更改时,它将使用FocusedRowKeyField更新浏览器地址窗口(仅在IE9中测试)。它还将调用代码隐藏中的脚本,该脚本将弹出一个带有该值的警报。每次焦点行更改都会触发Page_Load事件,您可能需要根据需要进行修改。您在哪里无法解析查询字符串?页面上是否发生了故障?你没有看到你的
页面加载中的值吗?@48klocs好的,我解决了数据绑定错误的问题,但是查询字符串仍然显示为空,使用fiddler或firebug来验证通过电线发送的内容。另外,基于这个问题(),您似乎应该使用window.location.href属性。好的,我的window.location.href
似乎没有通过发送
protected void Page_Load(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(Request.Params["FocusedRowKeyField"]))
{
GetClientDetails(Request.Params["FocusedRowKeyField"]);
}
<script type="text/javascript">
function OnGridFocusedRowChanged() {
grid.GetRowValues(grid.GetFocusedRowIndex(), 'ClassNR', OnGetRowValues);
}
function OnGetRowValues(ClassNR) {
window.location.href = "../main.aspx?FocusedRowKeyField=" + ClassNR;
}
<dx:ASPxGridView ID="grid" ClientInstanceName="grid" runat="server" EnableCallBacks="false" KeyFieldName="ClassNR">
<SettingsBehavior AllowSelectByRowClick="True" AllowSelectSingleRowOnly="True" ProcessFocusedRowChangedOnServer="false" AllowFocusedRow="true" />
<ClientSideEvents FocusedRowChanged="function(s,e) { OnGridFocusedRowChanged(); }" />
protected void Page_Load(object sender, EventArgs e)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "myScript", "<script language=JavaScript>alert(" + Request.Params["FocusedRowKeyField"] + ");</script>");
}