This is a migrated thread and some comments may be shown as answers.

[Solved] Specified argument was out of the range of valid values.

3 Answers 122 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Devanand Jha
Top achievements
Rank 1
Devanand Jha asked on 07 Aug 2009, 01:04 PM
Hi,

I am getting above error when clicking on edit link in RadGrid. It's working fine when column is specified in aspx page only, but when adding bound column dynamically its giving error.

My code :

 

<telerik:RadScriptManager ID="RadScriptManager1" runat="server" /> 

 

 

<telerik:RadGrid AutoGenerateColumns="false" ID="RadGrid1" OnNeedDataSource="RadGrid1_NeedDataSource"

 

 

 

AllowPaging="true" PageSize="10" AllowSorting="true" runat="server"

 

 

AutoGenerateEditColumn="true">

 

<ClientSettings>

 

 

 

<ClientEvents />

 

 

 

</ClientSettings>

 

 

<MasterTableView EditMode="InPlace" >

 

 

<Columns>

 

 

<%

 

--<telerik:GridBoundColumn HeaderText="Name" DataField="Name" UniqueName="Name" SortExpression="Name"></telerik:GridBoundColumn>--%>

 

</Columns>

 

 

</MasterTableView>

 

 

</telerik:RadGrid>
protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)

 

{

 

GridBoundColumn gBColumn = new GridBoundColumn();

 

gBColumn.HeaderText =

"Name";

 

 gBColumn.DataField =

"Name";

 

 gBColumn.UniqueName =

"Name";

 

 gBColumn.SortExpression =

"Name";

 

 RadGrid1.MasterTableView.Columns.Add(gBColumn);

RadGrid1.DataSource = GetDataSet();

}

Regards
Devanand Jha

 

 

3 Answers, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 07 Aug 2009, 01:27 PM
Hello Devanand,

Creating columns inside the NeedDataSource event handler of the control is not proper scenario as thus their viewstate will not be persisted properly. I suggest you follow the guidelines for runtime grid columns generation described in this help article and update your code accordingly to see whether this helps.

Best regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Devanand Jha
Top achievements
Rank 1
answered on 10 Aug 2009, 06:02 AM

Hello Sebastian,

Thanks for ur valuable feedback. I have made all the changes to dynamically creating column at runtime on Page_init. But i am facing problem as grid is not reloading on postback i.e Paging, sorting is not working and grid get disappeared. I think there is some viewstate problem, please suggest how can i achieve Paging, Sorting and editing here.

Here is my code:

 

 

protected void Page_Init(object sender, System.EventArgs e)

 

{

DefineGridStructure();

}

 

 

private void DefineGridStructure()

 

{

RadGrid1.DataSource = GetDataSet();

 

RadGrid1.Width =

Unit.Percentage(100);

 

RadGrid1.PageSize = 10;

RadGrid1.AllowSorting =

true;

 

RadGrid1.AllowPaging =

true;

 

RadGrid1.PagerStyle.Mode =

GridPagerMode.NextPrevAndNumeric;

 

RadGrid1.AutoGenerateColumns =

false;

 

 

 

GridBoundColumn boundColumn = new GridBoundColumn();

 

boundColumn.DataField =

"Name";

 

boundColumn.HeaderText =

"Customer Name";

 

RadGrid1.MasterTableView.Columns.Add(boundColumn);

boundColumn =

new GridBoundColumn();

 

boundColumn.DataField =

"ShortName";

 

boundColumn.HeaderText =

"Short Name";

 

RadGrid1.MasterTableView.Columns.Add(boundColumn);

}

is there something wrong??

Regards,
Devanand Jha

0
Tsvetoslav
Telerik team
answered on 12 Aug 2009, 09:21 AM
Hi Devanand,

If you are not creating the grid entirely in code behind it is best to use the Page_Load event following the directions for that in the help article my colleague has sent you.

Greetings,
Tsvetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
General Discussions
Asked by
Devanand Jha
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Devanand Jha
Top achievements
Rank 1
Tsvetoslav
Telerik team
Share this question
or