Telerik的radgrid控件 - 添加项目到下拉列表中通过文本框 [英] Telerik RadGrid - Adding Items into dropdown list by textbox

查看:257
本文介绍了Telerik的radgrid控件 - 添加项目到下拉列表中通过文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生/​​女士:

我要通过单击添加以显示RadTextbox作为InsertItem模板,然后单击输入所有DATAS内radgrid控件

在添加新记录开发插入命令

但是,当它进入了测试,发现获取的项目无法完成,并且始终显示为空

THW以下是我的code,请回答

 保护无效btnAddRecord_grdFlex_performInsert(对象发件人,EventArgs的发送)
    {
        RadButton对接=发件人为RadButton;        的foreach(GridDataItem的DataItem在grdFlex.MasterTableView.Items)
        {            RadTextBox textBox1的=(RadTextBox)(DataItem的[公司]的FindControl(txtSubcomName)。);
            RadTextBox TextBox2中=(RadTextBox)(DataItem的[FlexAcct code]的FindControl(txtFlex)。);
            radcombobox控件AB =(radcombobox控件)(DataItem的[公司]的FindControl(cboCompany)。);
            radcombobox控件CD =(radcombobox控件)(DataItem的[FlexAcct code]的FindControl(cboFlexAcct code));
            如果(!String.IsNullOrEmpty(textBox1.Text))
            {
                ab.Items.Insert(1,新RadComboBoxItem(textBox1.Text));
                ab.SelectedIndex = 0;
                textBox1.Text =的String.Empty;
            }            如果(!String.IsNullOrEmpty(textBox2.Text))
            {
                cd.Items.Insert(1,新RadComboBoxItem(textBox2.Text));
                cd.SelectedIndex = 0;
                textBox2.Text =的String.Empty;
            }
        }
    }   ASP://         < Telerik的:radgrid控件ID =grdFlex=服务器的AutoGenerateColumns =FALSE    ShowStatusBar =真AllowAutomaticDeletes =真AllowAutomaticInserts =真
    AllowAutomaticUpdates =真
     EnableDynamicPageSize =假
                        AllowMultiRowSelection =真EnableToolbar =FALSEOnNeedDataSource =grdFlex_NeedDataSource                        WIDTH =80%>
                        < MasterTableView CommandItemDisplay =TopAndBottom编辑模式=就地>
                            < CommandItemTemplate>
                                < D​​IV的风格=填充:5像素为5px;>
                                    < Telerik的:RadButton =服务器文本=添加新的ID =btnAdd_grdFlex的CommandName =InitInsert
                                        可见='<%#grdFlex.MasterTableView.IsItemInserted%GT;!'>
                                        <图标PrimaryIconUrl =〜/图像/按钮/ add.gifPrimaryIconLeft =8PrimaryIconTop =4/>
                                    < / Telerik的:RadButton>
                                    &安培; NBSP;&安培; NBSP;
                                    < Telerik的:RadButton =服务器的AutoPostBack =假文本=删除ID =btnDelete_grdFlex
                                        OnClientClicked =grdFlex_onDeleteClick的CausesValidation =false的可见='<%!#grdFlex.MasterTableView.IsItemInserted%GT;'>
                                        <图标PrimaryIconUrl =〜/图像/按钮/ remove.gifPrimaryIconLeft =8PrimaryIconTop =4/>
                                    < / Telerik的:RadButton>
                                    &安培; NBSP;&安培; NBSP;
                                    < Telerik的:RadButton =服务器文本=添加新记录ID =btnAddRecord_grdFlex的CommandName =PerformInsert按需=btnAddRecord_grdFlex_performInsert
                                        可见='<%#grdFlex.MasterTableView.IsItemInserted%GT;'>                                        <图标PrimaryIconUrl =〜/图像/按钮/ yes.gifPrimaryIconLeft =8PrimaryIconTop =4/>
                                    < / Telerik的:RadButton>
                                    &安培; NBSP;&安培; NBSP;
                                    < Telerik的:RadButton =服务器文本=取消编辑ID =btnCancel_grdCancel的CommandName =CancelAll
                                        可见='<%#&grdFlex.EditIndexes.Count GT; 0 || grdFlex.MasterTableView.IsItemInserted%GT;'>
                                        <图标PrimaryIconUrl =〜/图像/按钮/ cancel.gifPrimaryIconLeft =8PrimaryIconTop =4/>
                                    < / Telerik的:RadButton>
                                    &安培; NBSP;&安培; NBSP;
                                < / DIV>
                            < / CommandItemTemplate> ...........                                      < Telerik的:GridTemplateColumn UniqueName =公司的HeaderText =公司>
                                <&InsertTemplate则GT;
                                < Telerik的:RadTextBox ID =txtSubcomName=服务器>< / Telerik的:RadTextBox>
                                < / InsertTemplate则>
                                    <&ItemTemplate中GT;
                                        < Telerik的:radcombobox控件ID =cboCompany=服务器过滤器=包含AppendDataBoundItems =真AllowCustomText =真
                                            WIDTH =100%的SelectedValue ='<%#绑定(公司)%GT;'>
                                            <项目>
                                                < Telerik的:RadComboBoxItem文本=攸利建筑有限公司VALUE =YLC/>
                                                < Telerik的:RadComboBoxItem文本=攸利控股VALUE =YLH/>
                                            < /项目>
                                        < / Telerik的:radcombobox控件>
                                    < / ItemTemplate中>
                                    < ItemStyle WIDTH =200像素/>
                                < / Telerik的:GridTemplateColumn>
                                < Telerik的:GridTemplateColumn UniqueName =FlexAcct code的HeaderText =Flex的A / C code>
                             <&InsertTemplate则GT;


解决方案

我想你根据您code以下的例如

此演示使用自动插入它处理控件的值会自动以及使用数据源插入到数据库中。在你的情况下,你想通过code访问控制。

我不得不简化code跨越我的观点。这应该得到你所需要的。

C#

 保护无效RadGrid1_InsertCommand(对象源,GridCommandEventArgs E)
{
VAR的DataItem = e.Item为GridDataItem;
变种的textBox = dataItem.findControl(txtSubcomName)作为RadTextBox;
// ...得到这样的控件的其余部分
textBox2.Text = textBox.Text;
}

ASP.net

 < Telerik的:radgrid控件ID =RadGrid1=服务器
        OnInsertCommand =RadGrid1_InsertCommand>
        < MasterTableView的DataKeyNames =ID>
            <柱体和GT;
                < Telerik的:GridButtonColumn UniqueName =InsertColumn按钮类型=的ImageButton的CommandName =插入>
                < / Telerik的:GridButtonColumn>
< Telerik的:GridTemplateColumn UniqueName =公司的HeaderText =公司>
                                <&InsertTemplate则GT;
                                < Telerik的:RadTextBox ID =txtSubcomName=服务器>< / Telerik的:RadTextBox>
                                < / InsertTemplate则>
                                    <&ItemTemplate中GT;
                                        < Telerik的:radcombobox控件ID =cboCompany=服务器过滤器=包含AppendDataBoundItems =真AllowCustomText =真
                                            WIDTH =100%的SelectedValue ='<%#绑定(公司)%GT;'>
                                            <项目>
                                                < Telerik的:RadComboBoxItem文本=攸利建筑有限公司VALUE =YLC/>
                                                < Telerik的:RadComboBoxItem文本=攸利控股VALUE =YLH/>
                                            < /项目>
                                        < / Telerik的:radcombobox控件>
                                    < / ItemTemplate中>
                                    < ItemStyle WIDTH =200像素/>
                                < / Telerik的:GridTemplateColumn>
...格的休息

Sir/Madam,

I am going to develop a insert command by clicking Add to display the RadTextbox as InsertItem Templates and click Add New Record after inputting all the datas INside the RadGrid

But when it goes into the testing, it is found that Getting the Items cannot be done and always show null

thw following is my code , please answer

     protected void btnAddRecord_grdFlex_performInsert(object sender, EventArgs e)
    {
        RadButton butt = sender as RadButton;

        foreach (GridDataItem dataItem in grdFlex.MasterTableView.Items)
        {

            RadTextBox textBox1 = (RadTextBox)(dataItem["Company"].FindControl("txtSubcomName"));
            RadTextBox textBox2 = (RadTextBox)(dataItem["FlexAcctCode"].FindControl("txtFlex"));
            RadComboBox ab= (RadComboBox)(dataItem["Company"].FindControl("cboCompany"));
            RadComboBox cd= (RadComboBox)(dataItem["FlexAcctCode"].FindControl("cboFlexAcctCode"));


            if (!String.IsNullOrEmpty(textBox1.Text))
            {
                ab.Items.Insert(1, new RadComboBoxItem(textBox1.Text));
                ab.SelectedIndex = 0;
                textBox1.Text = String.Empty;
            }

            if (!String.IsNullOrEmpty(textBox2.Text))
            {
                cd.Items.Insert(1, new RadComboBoxItem(textBox2.Text));
                cd.SelectedIndex = 0;
                textBox2.Text = String.Empty;
            }
        }
    }

   ASP://



         <telerik:RadGrid ID="grdFlex" runat="server" AutoGenerateColumns="False"

    ShowStatusBar="true" AllowAutomaticDeletes="True" AllowAutomaticInserts="True"
    AllowAutomaticUpdates="True" 
     EnableDynamicPageSize="False"
                        AllowMultiRowSelection="true" EnableToolbar="False" OnNeedDataSource="grdFlex_NeedDataSource"

                        Width="80%">
                        <MasterTableView CommandItemDisplay="TopAndBottom" EditMode="InPlace"  >
                            <CommandItemTemplate>
                                <div style="padding: 5px 5px;">
                                    <telerik:RadButton runat="server" Text="Add new" ID="btnAdd_grdFlex"  CommandName="InitInsert"
                                        Visible='<%# !grdFlex.MasterTableView.IsItemInserted %>'>
                                        <Icon PrimaryIconUrl="~/Image/Button/add.gif" PrimaryIconLeft="8" PrimaryIconTop="4" />
                                    </telerik:RadButton>
                                    &nbsp;&nbsp;
                                    <telerik:RadButton runat="server" AutoPostBack="false" Text="Delete" ID="btnDelete_grdFlex" 
                                        OnClientClicked="grdFlex_onDeleteClick" CausesValidation="false" Visible='<%# !grdFlex.MasterTableView.IsItemInserted %>'>
                                        <Icon PrimaryIconUrl="~/Image/Button/remove.gif" PrimaryIconLeft="8" PrimaryIconTop="4" />
                                    </telerik:RadButton>
                                    &nbsp;&nbsp;
                                    <telerik:RadButton runat="server" Text="Add New record" ID="btnAddRecord_grdFlex" CommandName="PerformInsert" OnCommand="btnAddRecord_grdFlex_performInsert" 
                                        Visible='<%# grdFlex.MasterTableView.IsItemInserted %>'>

                                        <Icon PrimaryIconUrl="~/Image/Button/yes.gif" PrimaryIconLeft="8" PrimaryIconTop="4" />
                                    </telerik:RadButton>
                                    &nbsp;&nbsp;
                                    <telerik:RadButton runat="server" Text="Cancel editing" ID="btnCancel_grdCancel" CommandName="CancelAll"
                                        Visible='<%# grdFlex.EditIndexes.Count > 0 || grdFlex.MasterTableView.IsItemInserted %>'>
                                        <Icon PrimaryIconUrl="~/Image/Button/cancel.gif" PrimaryIconLeft="8" PrimaryIconTop="4" />
                                    </telerik:RadButton>
                                    &nbsp;&nbsp;
                                </div>
                            </CommandItemTemplate>

 ...........

                                      <telerik:GridTemplateColumn UniqueName="Company"  HeaderText="Company">
                                <InsertItemTemplate>
                                <telerik:RadTextBox ID="txtSubcomName" runat="server" ></telerik:RadTextBox>
                                </InsertItemTemplate>
                                    <ItemTemplate>
                                        <telerik:RadComboBox ID="cboCompany" runat="server" Filter="Contains"   AppendDataBoundItems="true" AllowCustomText="True"
                                            Width="100%" SelectedValue='<%# Bind("Company") %>'>
                                            <Items>
                                                <telerik:RadComboBoxItem Text="Yau Lee Construction Co. Ltd" Value="YLC" />
                                                <telerik:RadComboBoxItem Text="Yau Lee Holdings" Value="YLH" />
                                            </Items>
                                        </telerik:RadComboBox>
                                    </ItemTemplate>
                                    <ItemStyle Width="200px" />
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn UniqueName="FlexAcctCode" HeaderText="Flex A/C Code">
                             <InsertItemTemplate>

解决方案

I take it you based your code on the following example

This demo is using automatic inserts which handles the value of the controls automatically as well as uses the datasource to insert into the database. In you case you want access to the controls through code.

I had to simplify the code to get my point across. This should get what you need

C#

protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e)
{
var dataItem = e.Item as GridDataItem;
var textBox = dataItem.findControl("txtSubcomName") as RadTextBox;
//... get the rest of the controls like this
textBox2.Text = textBox.Text;
}

ASP.net

<telerik:RadGrid ID="RadGrid1" runat="server" 
        OnInsertCommand="RadGrid1_InsertCommand">
        <MasterTableView DataKeyNames="ID">
            <Columns>
                <telerik:GridButtonColumn UniqueName="InsertColumn" ButtonType="ImageButton" CommandName="Insert">
                </telerik:GridButtonColumn>
<telerik:GridTemplateColumn UniqueName="Company"  HeaderText="Company">
                                <InsertItemTemplate>
                                <telerik:RadTextBox ID="txtSubcomName" runat="server" ></telerik:RadTextBox>
                                </InsertItemTemplate>
                                    <ItemTemplate>
                                        <telerik:RadComboBox ID="cboCompany" runat="server" Filter="Contains"   AppendDataBoundItems="true" AllowCustomText="True"
                                            Width="100%" SelectedValue='<%# Bind("Company") %>'>
                                            <Items>
                                                <telerik:RadComboBoxItem Text="Yau Lee Construction Co. Ltd" Value="YLC" />
                                                <telerik:RadComboBoxItem Text="Yau Lee Holdings" Value="YLH" />
                                            </Items>
                                        </telerik:RadComboBox>
                                    </ItemTemplate>
                                    <ItemStyle Width="200px" />
                                </telerik:GridTemplateColumn>
... rest of grid

这篇关于Telerik的radgrid控件 - 添加项目到下拉列表中通过文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆