RadGrid 在编辑文本框的更改标签上 [英] RadGrid on Edit Change label of Text Box

查看:77
本文介绍了RadGrid 在编辑文本框的更改标签上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢在 Edit 上更改文本框的标签.我有问题因为我需要点击编辑功能两次才能做到这一点:

I like to change the label of the text box on Edit. I am having a problem in that I need to click on the edit feature twice for that to happen:

     <telerik:RadGrid runat="server" ID="rdReport" AutoGenerateColumns="false" AllowPaging="true" Skin="Metro"  OnItemCommand="ItemCommand" OnItemDataBound="rdReport_ItemDataBound" OnPreRender="rdReport_PreRender" DataSourceID="FountainSource" AllowAutomaticUpdates="true" AllowAutomaticDeletes="true">
                        <MasterTableView DataKeyNames="ID" CommandItemDisplay="None">
                            <Columns>
                                <telerik:GridEditCommandColumn ButtonType="ImageButton" />                                   
                                <telerik:GridBoundColumn DataField="LocName" HeaderText="Location" ReadOnly="true" /> 
                                <     
                                <telerik:GridBoundColumn DataField="Field1Value" HeaderText="Custom Field1" />
                                <telerik:GridBoundColumn DataField="Field2Value" HeaderText="Custom Field2" />
                                <telerik:GridBoundColumn DataField="Field3Value" HeaderText="Custom Field3" />

                                <telerik:GridButtonColumn ConfirmText="Delete?" ConfirmDialogType="RadWindow"
                                    ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" />
                            </Columns>
                            <EditFormSettings>
                                <EditColumn ButtonType="ImageButton" />
                            </EditFormSettings>
                        </MasterTableView>
                        <PagerStyle Mode="NextPrevAndNumeric" />
                    </telerik:RadGrid>

 protected void rdReport_ItemDataBound(object sender, GridItemEventArgs e)   
 {

  // Edit Mode
  if ((e.Item is GridEditFormItem) && (e.Item.IsInEditMode))   
  {  
        rdReport.MasterTableView.GetColumn("Field1").HeaderText =  "MyCustomFieldName";
  }
 }

推荐答案

请尝试使用以下代码片段.

Please try with the below code snippet.

ASPX

<telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource" OnItemDataBound="RadGrid1_ItemDataBound">
    <MasterTableView AutoGenerateColumns="false">
        <Columns>
            <telerik:GridBoundColumn DataField="Name" UniqueName="Name" HeaderText="Name"></telerik:GridBoundColumn>
            <telerik:GridEditCommandColumn></telerik:GridEditCommandColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

ASPX.CS

protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    dynamic data = new[] {
        new { ID = 1, Name ="Name1"},
        new { ID = 2, Name ="Name2"}
    };
    RadGrid1.DataSource = data;
}

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        GridEditableItem item = (GridEditableItem)e.Item;
        TextBox txtBox = (TextBox)item["Name"].Controls[0];
        (txtBox.Parent.Parent.Controls[0] as TableCell).Text = (txtBox.Parent.Parent.Controls[0] as TableCell).Text.Replace("Name:", "yourtext:");
    }
}

如果有任何问题,请告诉我.

Let me know if any concern.

这篇关于RadGrid 在编辑文本框的更改标签上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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