RadButton -单一点击方法,不工作在RadGrid edittitemtemplate内

本文关键字:工作 RadGrid edittitemtemplate 单一点 方法 RadButton | 更新日期: 2023-09-27 18:12:31

里面有一个RadGrid,里面有一个RadComboBoxasp ButtonEditItemTemplate .

下面是当前代码:

<telerik:GridTemplateColumn UniqueName="AccountCode" HeaderText="Account Code">
   <ItemTemplate>
       <asp:Label ID="lblAcCode" runat="server" Text='<%# Eval("AccountCode")%>'></asp:Label>
   </ItemTemplate>
   <EditItemTemplate>
       <telerik:RadComboBox ID="ddlAccountCode" runat="server" Height="200" Width="240" DropDownWidth="310"       
         EnableLoadOnDemand="True" OnItemsRequested="ddlAccountCode_ItemsRequested" EnableItemCaching="true"  
         ShowMoreResultsBox="True" EnableVirtualScrolling="true" AllowCustomText="true" MarkFirstMatch="true"
         Filter="Contains" HighlightTemplatedItems="true" CausesValidation="true" AppendDataBoundItems="true" 
         DataTextField="AccountDescription" DataValueField="AccountCodeID"
         ShowDropDownOnTextboxClick="false" 
         OnClientDropDownOpening="OnClientDropDownOpening" OnClientItemsRequested="OnClientItemsRequested"
         OnClientTextChange="LoadECnEntityKeys" />
       <asp:Button ID="btnSearch" runat="server" Text="Search" OnClient="btnSearch_Click" />
       &nbsp;
       <asp:Label ID="lblMsg" runat="server" Visible="false"></asp:Label>
   </EditItemTemplate>
</telerik:GridTemplateColumn>
protected void btnSearch_Click(object sender, EventArgs e)
{
     Response.Write("Default.aspx");
     //other code
}

当我在RadComboBox中输入/key-in一些东西并点击asp Button时,则在asp ButtonOnClick事件执行后,才开始显示与key-in文本相关的搜索。

现在,新的要求是放置RadButton(带- Single Click)方法)代替asp Button,以避免双击。

问题是:当我在RadGrid的EditItemTemplate内实现RadButton时,RadButton从不回发,即,当我点击它时什么都没有发生。但是当我在RadGrid之外使用时,相同的RadButton工作得很好。

下面是使用RadButton (- Single Click)的代码方法):

<telerik:GridTemplateColumn UniqueName="AccountCode" HeaderText="Account Code">
   <ItemTemplate>
       <asp:Label ID="lblAcCode" runat="server" Text='<%# Eval("AccountCode")%>'></asp:Label>
   </ItemTemplate>
   <EditItemTemplate>
       <telerik:RadComboBox ID="ddlAccountCode" runat="server" Height="200" Width="240" DropDownWidth="310"       
         EnableLoadOnDemand="True" OnItemsRequested="ddlAccountCode_ItemsRequested" EnableItemCaching="true"  
         ShowMoreResultsBox="True" EnableVirtualScrolling="true" AllowCustomText="true" MarkFirstMatch="true"
         Filter="Contains" HighlightTemplatedItems="true" CausesValidation="true" AppendDataBoundItems="true" 
         DataTextField="AccountDescription" DataValueField="AccountCodeID"
         ShowDropDownOnTextboxClick="false" 
         OnClientDropDownOpening="OnClientDropDownOpening" OnClientItemsRequested="OnClientItemsRequested"
         OnClientTextChange="LoadECnEntityKeys" />
       <telerik:RadButton runat="server" ID="btnSearch" Text="Search" SingleClick="true"
        SingleClickText="Submitting..." OnClick="btnSearch_Click" />
       &nbsp;
       <asp:Label ID="lblMsg" runat="server" Visible="false"></asp:Label>
   </EditItemTemplate>
</telerik:GridTemplateColumn>
protected void btnSearch_Click(object sender, EventArgs e)
{
     Response.Write("Default.aspx");
     //other code
}

请告诉我为什么会发生这种情况?请务必回复

Thanks in advance

RadButton -单一点击方法,不工作在RadGrid edittitemtemplate内

我建议您使用CommandName作为按钮事件。无论如何,这是我的代码…我试着使用OnClick和CommandName,它工作得很好。我怀疑你的错误将是某种javascript…

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" Width="100%" 
 OnNeedDataSource="RadGrid1_NeedDataSource" OnItemCommand="RadGrid1_ItemCommand" 
 OnItemDataBound="RadGrid1_ItemDataBound">
<MasterTableView EditMode="InPlace">
    <Columns>
        <telerik:GridTemplateColumn>
            <ItemTemplate>
                <asp:Label ID="lblAcCode" runat="server" Text='<%# Eval("T")%>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
                <telerik:RadComboBox ID="rcb" runat="server" AllowCustomText="true">
                </telerik:RadComboBox>
                <telerik:RadButton runat="server" ID="btnSearch" Text="Search" 
                 SingleClick="true" SingleClickText="Submitting..." CommandName="Search" />
            </EditItemTemplate>
        </telerik:GridTemplateColumn>
        <telerik:GridTemplateColumn>
            <ItemTemplate>
                <telerik:RadButton ID="btnEdit" runat="server" 
                 Text="Edit" CommandName="Edit"></telerik:RadButton>
            </ItemTemplate>
            <EditItemTemplate>
                <telerik:RadButton ID="btnCancel" runat="server" Text="Cancel" 
                 CommandName="Cancel"></telerik:RadButton>
            </EditItemTemplate>
        </telerik:GridTemplateColumn>
    </Columns>
</MasterTableView>

cs

protected void Page_Load(object sender, EventArgs e)
{
    // Check
    if (!IsPostBack)
    {
        // Variable
        DataTable dt = new DataTable();
        dt.Columns.Add("T");
        // Loop & Add
        for (int i = 0; i < 10; i++)
            dt.Rows.Add(i + "");
        // Check & Bind
        if (dt != null)
        {
            ViewState["Grid"] = dt;
            RadGrid1.DataSource = dt;
            RadGrid1.DataBind();
            // Dispose
            dt.Dispose();
        }
    }
}
protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
    RadGrid1.DataSource = ViewState["Grid"] as DataTable;
}
protected void btnSearch_Click(object sender, EventArgs e)
{
    Response.Write("GG");
}
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    // Check
    if (e.CommandName == "Search")
    {
        // Variable
        GridEditableItem item = e.Item as GridEditableItem;
        string something = "";
        // Find Control
        RadComboBox rcb = item.FindControl("rcb") as RadComboBox;
        // Check
        if (rcb != null)
        {
            // Set
            something = rcb.Text;
            // Do Something 
            Response.Write(something);
        }
    }
}
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    // Check
    if (e.Item is GridEditableItem)
    {
        // FindControl
        RadComboBox rcb = e.Item.FindControl("rcb") as RadComboBox;
        // Check
        if (rcb != null)
        {
            rcb.DataSource = ViewState["Grid"] as DataTable;
            rcb.DataTextField = "T";
            rcb.DataValueField = "T";
            rcb.DataBind();
        }
    }
}