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

[Solved] Accessing GridViewDataColumn in code behind.

2 Answers 257 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Abhishek Chauhan
Top achievements
Rank 1
Abhishek Chauhan asked on 26 Oct 2009, 01:32 PM
Hi,

I need to access a gridview datacolumn in code behind to bind the data ( my BDO object), set the header text and for some other reasons as my application is supposed to be highly configurable. I have a method that performs all these things and it takes GridViewDataColumn as one of the parameters but when I am calling this method, passing "x:Name" of the column it comes as null only. Please find below the datacolumn code and the method along with the method call-

Column-

 

 

<telerikGrid:GridViewDataColumn x:Name="colResultID">

 

 

 

<telerikGrid:GridViewDataColumn.CellTemplate>

 

 

 

<DataTemplate>

 

 

 

<TextBlock x:Name="txtblkResultID" />

 

 

 

</DataTemplate>

 

 

 

</telerikGrid:GridViewDataColumn.CellTemplate>

 

 

 

<telerikGrid:GridViewDataColumn.CellEditTemplate>

 

 

 

<DataTemplate>

 

 

 

<TextBox x:Name="txtboxResultID" />

 

 

 

</DataTemplate>

 

 

 

</telerikGrid:GridViewDataColumn.CellEditTemplate>

 

 

 

</telerikGrid:GridViewDataColumn>

 


Method-

 

private void SetGridConfiguration(Admin_ConfigBDO admin_ConfigBDO,

 

 

GridViewDataColumn column, string bindingName)

 

{

 

try

 

{

 

if (lstMyDisplayColumns.Contains(admin_ConfigBDO.DisplayName))

 

{

column.Header = admin_ConfigBDO.DisplayName;

column.IsReadOnly = admin_ConfigBDO.IsRead_only;

column.IsFilterable = admin_ConfigBDO.IsFilterField;

column.IsGroupable = admin_ConfigBDO.CanGroup_By;

 

//column.DataType = admin_ConfigBDO.DataType;

 

column.DataMemberBinding =

new Binding(bindingName);

 

}

 

else

 

{

rdgMitigationEvents.Columns.Remove(column);

}

}

 

catch (Exception ex)

 

{

}

}


Method Call (inside a web service completed event-

 

 

void svcAdminSoapClient_GetMitigationConfigDetailsCompleted(object sender, GetMitigationConfigDetailsCompletedEventArgs e)

 

{

 

try

 

{

admin_MitignConfigBDO = e.Result;

SetGridConfiguration(admin_MitignConfigBDO.ResultID, colResultID,

"ResultID");

 

}

 

catch (Exception ex)

 

{

}

}

the parameter colResultID always comes out to be null. The rest of the parametrs and other stuff is specific to my application and the only issue i have is the one mentioned above.....Please suggest me how to resolve this if anyone has ever came acroos with such issue.

Thanks in Advance,
Abhishek Chauhan

2 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 26 Oct 2009, 01:42 PM
Hi Abhishek,

Contains() method will work with column instance not with string - you can use UniqueName or Header instead.

All the best,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Abhishek Chauhan
Top achievements
Rank 1
answered on 26 Oct 2009, 03:35 PM
Hi Vlad,

Thanx for the quick reply but I am facing the problem with the below given piece of code-

column.Header = admin_ConfigBDO.DisplayName;

column.IsReadOnly = admin_ConfigBDO.IsRead_only;

column.IsFilterable = admin_ConfigBDO.IsFilterField;

column.IsGroupable = admin_ConfigBDO.CanGroup_By;

here column comes as null and even the method call it is coming null only.

The contains you are refering to isbeing used for the list.
In the code given below-

if (lstMyDisplayColumns.Contains(admin_ConfigBDO.DisplayName))

 

{

column.Header = admin_ConfigBDO.DisplayName;

column.IsReadOnly = admin_ConfigBDO.IsRead_only;

column.IsFilterable = admin_ConfigBDO.IsFilterField;

column.IsGroupable = admin_ConfigBDO.CanGroup_By;

 

 

 

//column.DataType = admin_ConfigBDO.DataType;

 

 

 

column.DataMemberBinding =

 

new Binding(bindingName);

 

}

lstMyDisplayColumns is actually a list and the controls goes inside the "if" loop as well but the "column" is null.

Thanks Again,
Abhishek

Tags
GridView
Asked by
Abhishek Chauhan
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Abhishek Chauhan
Top achievements
Rank 1
Share this question
or