RadComboBox LoadOnDemand方法未在运行时显示RadComboBox的SelectedValue

时间:2015-08-11 08:45:29

标签: c# asp.net telerik radgrid radcombobox

我正在关注按需加载功能的下方链接到RadGrid内部的RadComboBox。
链接: http://demos.telerik.com/aspnet-ajax/combobox/examples/populatingwithdata/autocompletesql/defaultcs.aspx
Inside RadComboBox中的绑定取决于从RadGrid之外的RadComboBox外部选择的Item。 即,如果外部RadComboBox具有项目:A,B,C,D,E等 Inside RadComboBox中的绑定将为:A1到An,B1到Bn,C1-Cn等,具体取决于从RadComboBox外部选择的项目。

现在我有3个问题:
1)如何将默认文字写为"选择项目"在使用第7个索引的c#代码,在ItemRequested事件下的内部ComboBox中?
2)在编辑/更新按钮中单击,RadComboBox选中的值未在运行时显示。我能够在调试模式下看到该值,但在运行时它从未显示。
3)上面一行中RadComboBox中的搜索功能在我这边没有按预期工作。
在演示中,搜索在A1到A100(总记录)中,并从A8 中返回msg 项目A1-A8 ....即,在所有项目中(A100) )它只到A8。
在我的身边,搜索是在A1到A50(ItemsPerPage)之间,并从A2000(总记录)中返回msg 项目A1到A50 ....即,在所有项目中(A2000)它明智地获得批处理/页面/ ItemPerPage,然后当我向下滚动它显示更多的搜索结果。
我不希望这种情况发生,我希望它应该像在Demo / Link中搜索一样工作。

以下是我目前的代码:
C#代码:

protected void RGGSTAcCode_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        //bind dropdwon while "Add" 
        string CompanyCode = ddlCompany.SelectedValue.ToString();
        GridEditableItem item = (GridEditableItem)e.Item;

        if (!(e.Item is IGridInsertItem))
        {
            RadComboBox rcb = (RadComboBox)item.FindControl("ddlAccountCode");
            //Select particular dropdown value while "Edit"
            Label lblAcCode2 = item.FindControl("lblAcCode2") as Label;
            if (!string.IsNullOrEmpty(lblAcCode2.Text))
            {
                rcb.SelectedValue = Session["AccountDescription"].ToString();
                string selVal = rcb.SelectedValue;
            }
        }
    }        
}    
public DataTable GetAccCode(string CompanyCode)
{
    SqlConnection con = new SqlConnection(strcon);
    SqlCommand cmd = new SqlCommand("[Invoice].[usp_tbl_AccountCode_DL_Test]", con);
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.AddWithValue("@CompanyCode", CompanyCode);
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    DataTable dt = new DataTable();
    try
    {
        con.Open();
        da.Fill(dt);
        con.Close();
    }
    catch (Exception ex)
    {
    }
    return dt;
}    
//#Load on Demand
private const int ItemsPerRequest = 50;

private static string GetStatusMessage(int offset, int total)
{
    if (total <= 0)
        return "No matches";

    return String.Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", offset, total);
}    
protected void ddlAccountCode_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
{
    string c = ddlCompany.SelectedValue.ToString();

    DataTable dt = new DataTable();
    dt = GetAccCode(c);

    RadComboBox combo = (RadComboBox)sender;

    int itemOffset = e.NumberOfItems;
    int endOffset = Math.Min(itemOffset + ItemsPerRequest, dt.Rows.Count);
    e.EndOfItems = endOffset == dt.Rows.Count;

    for (int i = itemOffset; i < endOffset; i++)
    {    
        combo.Items.Add(new RadComboBoxItem(dt.Rows[i]["AccountDescription"].ToString(), dt.Rows[i]["AccountDescription"].ToString()));
    }

    e.Message = GetStatusMessage(endOffset, dt.Rows.Count);
}
protected void ddlAccountCode_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
    string a = e.Value;
    Session["AccountCodeID"] = a;

    string b = e.Text;
    Session["AccountDescription"] = b;
}

HTML代码:

<telerik:RadComboBox ID="ddlCompany" runat="server" Height="200" Width="240"
          DropDownWidth="310" EmptyMessage="- Select Product -" HighlightTemplatedItems="true" CausesValidation="false"
          Filter="Contains" AppendDataBoundItems="true" AllowCustomText="true" AutoPostBack="true"
          DataTextField="Title" DataValueField="Code" OnSelectedIndexChanged="ddlCompany_SelectedIndexChanged">
        </telerik:RadComboBox>

        <br />

        <telerik:RadAjaxPanel ID="RadAjaxPanel4" runat="server">
                <telerik:RadGrid ID="RGGSTAcCode" runat="server"
                   ShowFooter="True" GroupingEnabled="False" ShowStatusBar="true" EmptyDataText="No record available." 
                   AllowAutomaticInserts="False" AllowAutomaticUpdates="False" AllowAutomaticDeletes="true" 
                   OnNeedDataSource="RGGSTAcCode_NeedDataSource" OnItemDataBound="RGGSTAcCode_ItemDataBound" 
                   OnInsertCommand="RGGSTAcCode_InsertCommand" OnDeleteCommand="RGGSTAcCode_DeleteCommand" 
                   OnUpdateCommand="RGGSTAcCode_UpdateCommand" OnItemCommand="RGGSTAcCode_ItemCommand">
                  <mastertableview ShowHeadersWhenNoRecords="true" autogeneratecolumns="false" datakeynames="AccountCodeID" InsertItemDisplay="Top"
                    insertitempageindexaction="ShowItemOnCurrentPage" ShowFooter="True" CommandItemDisplay="Top" ClientIDMode="Static">                                   
                         <Columns> 
                             <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn"></telerik:GridEditCommandColumn> 

                             <telerik:GridTemplateColumn UniqueName="AccountCode" HeaderText="Account Code">
                                <ItemTemplate>
                                  <asp:Label ID="lblAcCode" runat="server" Text='<%# Eval("AccountCode")%>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                   <asp:Label ID="lblAcCode2" runat="server" Text='<%# Eval("AccountCode") + " - " + Eval("AccountDescription")%>' Visible="false"></asp:Label>

                                   <telerik:RadComboBox ID="ddlAccountCode" runat="server" Height="200" Width="240" DropDownWidth="310" HighlightTemplatedItems="true" CausesValidation="true"       
                                       OnItemsRequested="ddlAccountCode_ItemsRequested" ItemsPerRequest="10"
                                       EnableLoadOnDemand="True" ShowMoreResultsBox="true" EnableVirtualScrolling="true"
                                       AutoPostBack="true" OnSelectedIndexChanged="ddlAccountCode_SelectedIndexChanged"

                                       Filter="Contains" AppendDataBoundItems="true" DataTextField="AccountDescription" DataValueField="AccountCodeID">
                                   </telerik:RadComboBox>                                   

                                </EditItemTemplate>
                             </telerik:GridTemplateColumn>

                             <telerik:GridBoundColumn DataField="AccountDescription" HeaderText="Description" UniqueName="AccountDescription" SortExpression="AccountDescription" InsertVisiblityMode="AlwaysHidden" ReadOnly="true" ></telerik:GridBoundColumn>
                             <telerik:GridBoundColumn aggregate="SUM" DataField="Amount" HeaderText="Amount" FooterAggregateFormatString="Total : {0:###,##0.00}" DataFormatString="{0:n}" FooterStyle-BackColor="#ffc04c" UniqueName="Amount" SortExpression="Amount"></telerik:GridBoundColumn>
                             <telerik:GridBoundColumn DataField="Remark" HeaderText="IFCA Remark" UniqueName="Remark" SortExpression="Remark">

                             </telerik:GridBoundColumn>    

                             <telerik:GridButtonColumn ConfirmTextFormatString="Are you sure you want to Delete {0} Account Code?" ConfirmTextFields="AccountCodeID"
                             ConfirmDialogType="RadWindow" CommandName="Delete" Text="Delete" UniqueName="DeleteColumn"></telerik:GridButtonColumn>                                                                            
                      </Columns>
                      <EditFormSettings>
                         <EditColumn ButtonType="ImageButton" />
                      </EditFormSettings>
                      <CommandItemSettings AddNewRecordText="Add new record" RefreshText="Refresh"></CommandItemSettings>
                  </mastertableview>
                </telerik:RadGrid>      
        </telerik:RadAjaxPanel>

我无法解决上述3个问题。请回复。
请注意我是Telerik的新手。提前致谢

0 个答案:

没有答案