Telerik Forums
UI for ASP.NET AJAX Forum
5 answers
889 views
Hello!

I'm having problems with accessing a radgrids columns manually added from source code, I have loads of columns, and I don't want to repeat myself, adding the Width and change the headertext, according to my algorithm manually on each column.

Therefore I've been trying to find a way to set them automatically in the codebehind, however I am having problems accessing all the columns and settings. 

The columns is as said not generated automatically.

Any idea?

Before When I have had the columns auto generated I have easily achieved this by using the Event ColumnCreated

protected void radGrid_ColumnCreated(object sender, GridColumnCreatedEventArgse)
{
                e.Column.HeaderStyle.Width = 200;
                e.Column.ItemStyle.Width = 200;
                e.Column.HeaderText = "test";
               e.Column.UniqueName = "test2"
}

Now I want to do the same but with manually added columns? (The ColumnCreated event is only triggered when the columns are auto generated, sadly =()

So something like this, by what I assume listening to the ItemDataBound event?

protected void radGrid_ItemDataBound(object sender, GridItemEventArgs e)
{
      //Set column Width and Height and also the columns Header text and Unique name.
 }



Appreciate any help :) Hope I made it clear enough to understand :) 

Thanks in advance! ( Couldnt find any threads similair that accessed the HeaderStyle nor the UniqueName properties of a column)
Nicklas
Top achievements
Rank 1
 answered on 25 Jun 2013
2 answers
106 views
Hi there,
I created a control that inherits from RadGrid to include a RadWindow editing feature, similar to the sample here http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridandwindow/defaultcs.aspx?product=grid
The main difference is that I do not want to use an external page, as in the sample above, but I want to use a template to be dynamically loaded in the RadWindow. Also, I'd like to handle all load & save events using the RadGrid ItemCommand.
So I created an ITemplate EditWindowTemplate property in my control and I instantiate it in the RadWindow contentcontainer when needed.
This is the code I use to extend the RadGrid js client 
Telerik.Web.UI.RadGrid.prototype.showEditItemForm = function (itemIndex) {
    this.gridItemIndex = itemIndex;
    $find(this.windowId).show();
    __doPostBack(this.panelId, itemIndex);
    return false;
}
Telerik.Web.UI.RadGrid.prototype.saveChanges = function () {
    if (this.gridItemIndex > -1)
        this.get_masterTableView().fireCommand('Update', '');
    else
        this.get_masterTableView().fireCommand('PerformInsert', '');
}
So, when the user click the "Add new" link or an Edit link, I start a partial postback that loads the RadWindow contents, using an UpdatePanel.
This is the UpdatePanel PreRender method I use to display the UI and pass the edit item index to the server
void pnlWnd_PreRender(object sender, EventArgs e)
        {
            //Handle updatepanel postback, show edit window
            string eventTarget = HttpContext.Current.Request.Params["__EVENTTARGET"] as string;
            int eventArg = -1;
            if (!string.IsNullOrEmpty(eventTarget) && eventTarget == pnlWnd.ClientID && int.TryParse(HttpContext.Current.Request.Params["__EVENTARGUMENT"], out eventArg))
            {
                //CreateEditWindow();
                editWindowContainer.Visible = true;
                if (eventArg > -1)
                {
                    GridCommandEventArgs args = new GridCommandEventArgs(this.Items[eventArg], this, new CommandEventArgs(RadGrid.EditCommandName, null));
                    OnItemCommand(args);
                }
                else
                {
                    MasterTableView.IsItemInserted = true;
                    GridCommandEventArgs args = new GridCommandEventArgs(MasterTableView.GetItems(GridItemType.CommandItem)[0], this, new CommandEventArgs(InitInsertCommandName, -1));
                    OnItemCommand(args);
                }
            }
        }
If the user clicks on the Add link, I fire the InitInsert event, if he clicks an Edit link I fire the Edit event.
Last, I handle the ItemCommand event in a page to respond to each event: Edit (load an item and show the edit form), InitInsert (show empty edit form), Update (the user saved a change) and PerformInsert (the user saved a new item).
When I create a new item everything works, but when I try to save a change to an existing item I get

Specified argument was out of the range of valid values.
Parameter name: ItemHierarchicalIndex

What am I doing wrong?
Thanks!
Luca B
Top achievements
Rank 1
 answered on 25 Jun 2013
1 answer
60 views
Hello every one

i have radgride to show invoices list when i edit invoice in radwindow he show me the data for previous invoice

for example
When I try to edit invoice no 1 he show me the data correct in radwindow for first time
but after close radwindow then I try to edit invoice no 2 he show me in radwindow the data for invoice no 1


any one can help me

Thanks
Marin Bratanov
Telerik team
 answered on 25 Jun 2013
1 answer
138 views

Hello everyone,

i need your help for getting the value of the DataField from ClientDataKeyNames array of the MasterTable and even without AllowRowSelect = "True" 
All I need is to CLICK BUTTON ONLY WITHOUT AllowRowSelect = True 
Once I click "Remove Location" button, I am still getting error that we don't get any values from ClientDataKeyName.  

In UserControl 
<telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
        <script type="text/javascript">
            function OnClientClickingApprovedLocations(sender, args) {
                var callBackFunction2 = Function.createDelegate(sender, function (argument) {
                    if (argument) {
                        this.click();
                    }
                });
 
                var Master = $find("<%=rgRequestorlocations.ClientID %>").get_masterTableView();
                var SelectedItem = Master.get_selectedItems()[0];
 
                var location_name = SelectedItem.getDataKeyValue("location_name"); // get the DataKeyValue of selected item
                var role = SelectedItem.getDataKeyValue("role");
                var duty = SelectedItem.getDataKeyValue("duty");
 
 
                if (duty == "P") {
                    if (role == "Privacy Officer") {
 
                        roletext = "Are you sure you want to remove this role location?";
                        radconfirm(roletext, callBackFunction2, 300, 100, null, "Delete");
                        args.set_cancel(true);
                    }
                    else {
                        roletext = "Please confirm the Primary " + role + " for " + location_name + " will be removed " + "" + "?";
                        radconfirm(roletext, callBackFunction2, 300, 100, null, "Delete");
                        args.set_cancel(true);
                    }
 
                }
                else {
                    roletext = "Are you sure you want to remove this role location?";
                    radconfirm(roletext, callBackFunction2, 300, 100, null, "Delete");
                    args.set_cancel(true);
                }
            }
        </script>
    </telerik:RadScriptBlock>

<telerik:RadGrid ID="rgRequestorlocations" runat="server" AutoGenerateColumns="False" CellSpacing="0" GridLines="None" OnNeedDataSource="rgRequestorlocations_NeedDataSource" OnItemCommand="rgRequestorlocations_ItemCommand" OnItemDataBound="rgRequestorlocations_ItemDataBound">
                                            <MasterTableView DataKeyNames="location_pk, user_id, role,location_name, duty" ClientDataKeyNames="location_pk, user_id, role,location_name, duty">
 
                                                <CommandItemSettings ExportToPdfText="Export to PDF" />
                                                <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" Visible="True">
                                                    <HeaderStyle Width="20px" />
                                                </RowIndicatorColumn>
                                                <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True">
                                                    <HeaderStyle Width="20px" />
                                                </ExpandCollapseColumn>
                                                <Columns>
                                                    <telerik:GridBoundColumn DataField="user_id" FilterControlAltText="Filter location_pk column" HeaderText="User ID" UniqueName="user_id" Visible="False"></telerik:GridBoundColumn>
                                                    <telerik:GridBoundColumn DataField="location_pk" FilterControlAltText="Filter location_pk column" HeaderText="Location ID" UniqueName="location_pk" Visible="False"></telerik:GridBoundColumn>
                                                    <telerik:GridBoundColumn DataField="location_name" FilterControlAltText="Filter location_name column" HeaderText="Location Name" UniqueName="location_name"></telerik:GridBoundColumn>
                                                    <telerik:GridBoundColumn DataField="role" FilterControlAltText="Filter role column" HeaderText="Role" UniqueName="role"></telerik:GridBoundColumn>
                                                    <telerik:GridBoundColumn DataField="duty" FilterControlAltText="Filter role column" HeaderText="duty" UniqueName="duty" Visible="false"></telerik:GridBoundColumn>
                                                    <%--             <telerik:GridButtonColumn ButtonType="PushButton" FilterControlAltText="Filter deletecolumn column" ConfirmText="Are you sure you want to remove this role location?"
                                ConfirmDialogType="RadWindow"
                                ConfirmTitle="Remove Role Location?" HeaderText="Remove Role" Text="Remove Role" UniqueName="deletecolumn" CommandName="DeleteRoleLocation">
                            </telerik:GridButtonColumn>--%>
                                                    <telerik:GridTemplateColumn UniqueName="rbDelete">
                                                        <ItemTemplate>
                                                            <telerik:RadButton ID="rbDelete" onr runat="server" Text="Remove Role" OnClientClicking="OnClientClickingApprovedLocations" Value="" CommandName="DeleteRoleLocation">
                                                            </telerik:RadButton>
                                                        </ItemTemplate>
                                                    </telerik:GridTemplateColumn>
                                                </Columns>
                                                <EditFormSettings>
                                                    <EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
                                                </EditFormSettings>
                                                <PagerStyle PageSizeControlType="RadComboBox" />
                                            </MasterTableView>
                                            <PagerStyle PageSizeControlType="RadComboBox" />
                                            <ClientSettings>
                                                <Selecting AllowRowSelect="True"></Selecting>
 
                                            </ClientSettings>
 
                                            <FilterMenu EnableImageSprites="False"></FilterMenu>
                                        </telerik:RadGrid>

Eyup
Telerik team
 answered on 25 Jun 2013
1 answer
100 views
Hello friends
 
    I want to count telerik:GridBoundColumn in the radgrid so how can i do this?
Princy
Top achievements
Rank 2
 answered on 25 Jun 2013
3 answers
219 views
How to get Export working with GridButtonColumns ?  I want my LinkButton.Text data in the exported excel.


Shinu explains the problem here:
http://www.telerik.com/community/forums/aspnet-ajax/grid/exporting-data-to-excel.aspx#526940

but that link is not sufficient and does not present a solution.

Thanks.
Kostadin
Telerik team
 answered on 25 Jun 2013
1 answer
294 views
Hi,

I have a number of RadNumericTextboxes that all link to the same ValueChanged clientside event.
In this event I want to get the parent element of this RadNumericTextbox (a table cell) and change its background color.
However I have trouble getting the parent element. The RadNumericTextbox doesn't support the regular javascript 'parentNode' property so I can't use that. And I also have trouble selecting the RadNumericTextbox as a 'regular' DOM element because it's in a page with a masterpage, so the ID is useless.

Can anyone help?

Cheers,
CJ
Eyup
Telerik team
 answered on 25 Jun 2013
1 answer
255 views
Good day,

We're using one fileexplorer in a page.
When we press the 'Upload' button of the file explorer, a window appears with file selector open button, overwrite flag, filter label, etc.
We are unable to understand how to position and size the Upload window.

How can we change size and position when opening the Upload window?

We'd like to also know:
- Is it possible to change the 'Filename' and 'Size' labels of the file explorer?
- Is it possible to set size and position of the -file open- window (the one that appears when pressing 'Select' in the upload window)?

Thanks in advance
Ivaylo
Telerik team
 answered on 25 Jun 2013
8 answers
348 views
Hi.  I'm using an AjaxPanel for async postbacks.  Within that, I have a Rad File Upload control.  For file uploads, I turn off Ajax via set_enableAjax(false).  The file upload works correctly -- a full postback occurs.

After the full postback, if I then make some async postbacks within that AjaxPanel (which hides and unhides controls), when the Rad File Upload control becomes visible again, the styling for the Rad File Upload has disappeared.

I can see in Firebug that the first time the File Upload control appears, there are about 6 <link> tags in the <head> section for Telerik WebResource files.  When the styling is missing for the File Upload control, there is only about 1 WebResource <link> tag in the <head> section.  These missing WebResource files are causing the styling issues.

If I never upload a file (meaning there is no full postback), and I do several ajax postbacks, each time the File Upload control appears again, it is styled correctly everytime.  So it's only after a full postback, and then when I make a subsequent partial postback to make the File Upload control appear again, is this problem occurring.

I'm using Q1 2010.  Same problem is occurring in IE and Firefox.  I'm not seeing any errors in the Firefox Error Console.  I think this is a problem on the server side code not injecting the WebResource files in this scenario.  Any help is appeciated -- thanks.
Hristo Valyavicharski
Telerik team
 answered on 25 Jun 2013
1 answer
226 views
Hello friends,

I am using a RadTextBox, laying on a RadWindow and I want to make an ajax request from that control when the OnTextChange event is triggered. I am trying to use the following :
ScriptManager : This is the content page and the master page has got a script manager as below:
  • <body>
        <form id="form1" runat="server">
        <telerik:RadScriptManager ID="scriptSchMaster" runat="server" EnablePartialRendering="true"
            EnableScriptCombine="true" OnAsyncPostBackError="scriptSchMaster_AsyncPostBackError">
            <Scripts>
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js">
                </asp:ScriptReference>
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js">
                </asp:ScriptReference>
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js">
                </asp:ScriptReference>
            </Scripts>
        </telerik:RadScriptManager>
        <telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server">
        </telerik:RadStyleSheetManager>
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        </telerik:RadAjaxManager>
        <telerik:RadSkinManager ID="RadSkinManager1" runat="server">
            <TargetControls>
                <telerik:TargetControl ControlsToApplySkin="<Rad Controls>" Skin="<some valid skin name>" />
                <telerik:TargetControl ControlsToApplySkin="<Rad Controls>" Skin="<some valid skin name>" />
                ...
.aspx code snippet

<label>Product #</label><br />
<telerik:RadTextBox ID="tbProductNumber" runat="server" Width="250" CssClass="upperCase"
        AutoPostBack="true" MaxLength="30" OnTextChanged="tbProductNumber_OnTextChanged"
        EmptyMessage="Required" EnableViewState="true"
        EmptyMessageStyle-CssClass="validatorText">
 
            <ClientEvents OnBlur="jsfun_tbProductOnBlur" />
 
</telerik:RadTextBox>
 
<asp:UpdatePanel ID="upCheckProductNumber" runat="server" UpdateMode="Always">
     <ContentTemplate>
        <asp:Label ID="lblCheckProductResult" runat="server"></asp:Label>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="tbProductNumber" EventName="TextChanged" />
    </Triggers>
</asp:UpdatePanel><br />
<label id="lblProductNumValidator"></label>


.js code

function jsfun_tbProductNumberOnBlur(sender, args) {
    elem_ProductNumber = $find('<%=tbProductNumber.ClientID %>');
    if (
            elem_ProductNumber.get_value() != null &&
            elem_ProductNumber.get_value() != undefined
        )
                ProductNoEmpty = false;
            else
                ProductNoEmpty = true;
 
            showErrors();
 
            //__doPostBack('', '');
}


.aspx.cs code snippet: (This is not being called)

protected void tbProductNumber_OnTextChanged(object sender, EventArgs e)
{
        lblCheckProductNumberResult.Text = "Hello Ajax!";
}


I tried something in a separate sample application and it seemed to be working for textbox and radtextbox, both ...

.aspx content page

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <asp:ScriptManager runat="server">
    </asp:ScriptManager>
    <br />
    <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True" OnTextChanged="txtChanged"></asp:TextBox>
    <telerik:RadTextBox ID="radTextBox1" runat="server" AutoPostBack="true" OnTextChanged="txtChanged">
    </telerik:RadTextBox>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="TextBox1" EventName="TextChanged" />
            <asp:AsyncPostBackTrigger ControlID="radTextBox1" EventName="TextChanged" />
        </Triggers>
    </asp:UpdatePanel>
    <br />
    <input id="Text1" type="text" /><br />
    <br />
    <asp:Button ID="Button1" runat="server" Text="Button" />
    <br />
</asp:Content>


code behind
public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object senderEventArgs e)
        {
 
        }
        protected void txtChanged(object senderEventArgs e)
        {
            Label1.Text = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt");
            
        }
    }

Any help 'd be appreciated ...

Thanks,
-Aarsh
Vasil
Telerik team
 answered on 25 Jun 2013
Narrow your results
Selected tags
Tags
+? more
Top users last month
Ambisoft
Top achievements
Rank 2
Iron
Pascal
Top achievements
Rank 2
Iron
Matthew
Top achievements
Rank 1
Sergii
Top achievements
Rank 1
Iron
Iron
Andrey
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Ambisoft
Top achievements
Rank 2
Iron
Pascal
Top achievements
Rank 2
Iron
Matthew
Top achievements
Rank 1
Sergii
Top achievements
Rank 1
Iron
Iron
Andrey
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?