【问题标题】:update Telerik RadGrid by outside controls using ajax使用 ajax 通过外部控件更新 Telerik RadGrid
【发布时间】:2012-01-21 09:42:53
【问题描述】:

当搜索按钮被触发时,我希望在不刷新页面的情况下重新加载网格 我用过 PostBackTrigger 但它不适合我

这是我的 code.aspx 的一部分

<telerik:RadScriptManager ID="RadScriptManager1" runat="server" />

<asp:TextBox runat="server" ID="txtSearch"/>
<asp:Button Text="Search" runat="server" ID="btnSearch" OnClick="btnSearch_Click" />

<asp:UpdatePanel runat="server" ID="pnlUpdate">
<ContentTemplate>
  <rad:RadGrid id="RadGrid1" runat="server" EnableAJAX="True">
   <MasterTableView AutoGenerateColumns="False">
    <Columns>
     <rad:GridBoundColumn HeaderText="CustomerID" DataField="CustomerID"
      UniqueName= "CustomerID"></rad:GridBoundColumn>
     <rad:GridBoundColumn HeaderText="ContactName" DataField="ContactName"
      UniqueName= "ContactName"></rad:GridBoundColumn>
    </Columns>
   </MasterTableView>
 </rad:RadGrid>
</ContentTemplate>
    <Triggers>
        <asp:PostBackTrigger ControlID="btnSearch" />
    </Triggers>
</asp:UpdatePanel>

那么有什么技巧可以解决这个问题吗?? 谢谢大家

米兰门德帕拉

【问题讨论】:

  • 你在Code-Behind文件中做了什么来绑定数据?如果启用 Ajax,为什么不使用 AsyncPostBackTrigger?
  • 感谢 lloyd 的回复,我也尝试过使用 AsyncPostBackTrigger 但它也无法正常工作 .. 从代码隐藏中我启用分页并使用新数据源重新绑定网格 .. 在 grid_NeedDataSource() 中跨度>
  • Post你的代码在代码后面,你需要在Button点击事件中绑定。

标签: c# asp.net asp.net-ajax telerik-grid


【解决方案1】:

您没有为按钮的 OnClick 或 OnCommand 定义任何 Button 'Click' EventHandlers。确保您没有在 Page_Load 或 Page_Init 事件中无条件地绑定您的数据,检查页面是否没有处理回发。

<asp:Button Text="Search" OnClick="btnSearch_Click" runat="server" ID="btnSearch" />

// Change <asp:PostBackTrigger ControlID="btnSearch" />
<asp:AsyncPostBackTrigger ControlID="btnSearch" />

// Code Behind EventHandler
protected void btnSearch_Click(object sender, EventArgs e)
{
    // Retrieve and Bind Search Data to RadGrid1
    // You must Bind or Rebind the Datasource to the RadGrid control using the Bind() or Rebind() methods.
 }


// Check Databind is conditional if required
protected void Page_Load(object sender, EventArgs e)
{
    If (!Page.IsPostBack)
    {
        // Bind Data if required
    }    

}

【讨论】:

  • 对不起劳埃德我已经定义了 OnClick 但在这里我在发布问题时忘记写了.. 我刚刚纠正了我的错误
  • 页面是否正在回发?代码隐藏文件中的事件处理程序代码是什么?
  • protected void btnSearch_Click(object sender, EventArgs e) { ViewState["serVal"] = txtSearch.Text; grid.CurrentPageIndex = 0;网格.重新绑定(); } protected void grid_NeedDataSource(object source, GridNeedDataSourceEventArgs e) { if (ViewState["serVal"] == null) ViewState["serVal"] = ""; TestGridDataContext context = new TestGridDataContext(); List resultData = context.Employees.Where(emp => emp.empName.Contains(ViewState["serVal"].ToString())).ToList(); grid.DataSource = 结果数据; }
  • 您没有将数据绑定到您调用 RadGrid1.Bind() 或 RadGrid1.Rebind() 的网格;
  • 好吧,我写的太受保护了 void btnSearch_Click(object sender, EventArgs e) { ViewState["serVal"] = txtSearch.Text; grid.CurrentPageIndex = 0; RadGrid1.Rebind(); } 但还是一样的情况..
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-16
  • 2011-04-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-06
相关资源
最近更新 更多