I create columns of my grid dynamically on the server side. These are not created on the client side.
I need to check the name of the first column to this radgrid.
How is this possible ?
I actually tried
var gridID = $find("<%=RadgridDataAval.ClientID %>");
var x = gridID.get_masterTableView().getColumnByUniqueName("Error");
if (x)
alert ("exists");
else
alert("doesnt exist");
Error is the name of one of the columns of the grid. However, says it doesn't exist
Also, I don't know if we have examples that show how to fetch colulmn name of a particular column in the mastertableview on the client side.
SOS
thanks,
Jas
I need to check the name of the first column to this radgrid.
How is this possible ?
I actually tried
var gridID = $find("<%=RadgridDataAval.ClientID %>");
var x = gridID.get_masterTableView().getColumnByUniqueName("Error");
if (x)
alert ("exists");
else
alert("doesnt exist");
Error is the name of one of the columns of the grid. However, says it doesn't exist
Also, I don't know if we have examples that show how to fetch colulmn name of a particular column in the mastertableview on the client side.
SOS
thanks,
Jas
10 Answers, 1 is accepted
0
Shinu
Top achievements
Rank 2
answered on 08 Dec 2008, 05:04 AM
Hi Jas,
I tried this on my end and it is working fine. Have you set the correct column UniqueName? I would suggest you send your aspx code.
Here is the code I tried.
ASPX:
CS:
JS:
Thanks
Shinu.
I tried this on my end and it is working fine. Have you set the correct column UniqueName? I would suggest you send your aspx code.
Here is the code I tried.
ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" GridLines="None"> |
<MasterTableView> |
</MasterTableView> |
</telerik:RadGrid> |
CS:
protected void Page_Load(object sender, EventArgs e) |
{ |
if (!IsPostBack) |
{ |
RadGrid1.DataSourceID ="SqlDataSource1"; |
RadGrid1.Width = Unit.Percentage(98); |
RadGrid1.PageSize = 5; |
RadGrid1.AllowPaging = true; |
RadGrid1.AutoGenerateColumns = false; |
RadGrid1.Skin = "Web20"; |
RadGrid1.MasterTableView.PageSize = 15; |
RadGrid1.MasterTableView.Width = Unit.Percentage(100); |
//Add GridBoundColumn |
GridBoundColumn boundColumn; |
boundColumn = new GridBoundColumn(); |
RadGrid1.MasterTableView.Columns.Add(boundColumn); |
boundColumn.DataField = "ProductName"; |
boundColumn.HeaderText = "ProductName"; |
boundColumn.UniqueName = "ProductName"; |
} |
} |
JS:
<script type="text/javascript"> |
function ShowColumnName() |
{ |
alert('Hi'); |
var gridID = $find("<%=RadGrid1.ClientID %>"); |
var x = gridID.get_masterTableView().getColumnByUniqueName("ProductName"); |
if (x) |
alert ("exists"); |
else |
alert("doesnt exist"); |
} |
</script> |
Thanks
Shinu.
0
Jas
Top achievements
Rank 1
answered on 08 Dec 2008, 05:13 AM
Hi Shinu,
Actually I create a data table on the server side .
DataTable ddt = new DataTable();
ddt.Columns.Add("ERRORCODE", typeof(string));
and then set the data source of my radgrid equals to this data table.
Then does it really set the unique name for the radgrid columns if i create my radgrid like this ?
Just wondering . I really don't do it the way you created columns
Thanks,
Jas
Actually I create a data table on the server side .
DataTable ddt = new DataTable();
ddt.Columns.Add("ERRORCODE", typeof(string));
and then set the data source of my radgrid equals to this data table.
Then does it really set the unique name for the radgrid columns if i create my radgrid like this ?
Just wondering . I really don't do it the way you created columns
Thanks,
Jas
0
Jas
Top achievements
Rank 1
answered on 08 Dec 2008, 05:26 AM
Also,
how do i get the name of all the columns of the radgrid on client side ? is there any way to do that ?
Thanks
Jas
how do i get the name of all the columns of the radgrid on client side ? is there any way to do that ?
Thanks
Jas
0
Princy
Top achievements
Rank 2
answered on 08 Dec 2008, 10:54 AM
Hi Jas,
I guess you have set AutoGenerateColumns to true. If so the name of the column will be the Column UniqueName.
You can access all the columns in a Grid on the client side as shown below.
ASPX:
JS:
Regards
Princy
I guess you have set AutoGenerateColumns to true. If so the name of the column will be the Column UniqueName.
You can access all the columns in a Grid on the client side as shown below.
ASPX:
<input id="Button1" type="button" onclick="GetColumnNames();" value="button" /> |
JS:
<script type="text/javascript"> |
function GetColumnNames() |
{ |
var grid = $find("<%=RadGrid1.ClientID %>"); |
var columnCount = grid.get_masterTableView().get_columns().length; |
for(var i=0;i<columnCount;i++) |
{ |
var UniqueName=grid.get_masterTableView().get_columns()[i].get_uniqueName(); |
alert(UniqueName) |
} |
} |
</script> |
Regards
Princy
0
Achuthan
Top achievements
Rank 1
answered on 15 Oct 2012, 08:37 AM
Hi,
how do i get the name of all the columns of the radgrid in C#?
protected void RadGrid1_DataBound(object sender, EventArgs e)
{
// Here i am trying to access the column names of Radgrid for implement the Multiple column header.
var count= RadGrid1.Columns.Count;
//but the count value is always zero.
}
how do i get the name of all the columns of the radgrid in C#?
protected void RadGrid1_DataBound(object sender, EventArgs e)
{
// Here i am trying to access the column names of Radgrid for implement the Multiple column header.
var count= RadGrid1.Columns.Count;
//but the count value is always zero.
}
0
Shinu
Top achievements
Rank 2
answered on 15 Oct 2012, 08:48 AM
Hi,
You can loop through the columns as shown below.
C#:
Thanks,
Shinu.
You can loop through the columns as shown below.
C#:
protected
void
Button1_Click(
object
sender, EventArgs e)
{
foreach
(GridColumn col
in
RadGrid1.Columns)
{
string
value = col.UniqueName.ToString();
}
}
Thanks,
Shinu.
0
Sheshagiri
Top achievements
Rank 1
answered on 15 Sep 2014, 09:48 AM
Hi,
I have two table like Task and Task History, with different column names for key reference(taskID(primary key in Task) and taskhID(foreign key in Task History) i want to bind this two table to rad grid.
Problem is,
while binding if i use taskhID, then
protected void radgv_OnDetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e)
{
GridDataItem dataitem = (GridDataItem)e.DetailTableView.ParentItem;
if (e.DetailTableView.Name == "TaskHistory")
{
string id = dataitem.GetDataKeyValue("taskhID").ToString(); //error: Object reference not set to an instance of an object
e.DetailTableView.DataSource = GetDataTable("SELECT * FROM TaskHistory where taskhID= '" + id + "'");
}
Becouse column "taskID" is not exit in Table TaskHistory.
Please tell me the solution.
I have two table like Task and Task History, with different column names for key reference(taskID(primary key in Task) and taskhID(foreign key in Task History) i want to bind this two table to rad grid.
Problem is,
while binding if i use taskhID, then
protected void radgv_OnDetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e)
{
GridDataItem dataitem = (GridDataItem)e.DetailTableView.ParentItem;
if (e.DetailTableView.Name == "TaskHistory")
{
string id = dataitem.GetDataKeyValue("taskhID").ToString(); //error: Object reference not set to an instance of an object
e.DetailTableView.DataSource = GetDataTable("SELECT * FROM TaskHistory where taskhID= '" + id + "'");
}
Becouse column "taskID" is not exit in Table TaskHistory.
Please tell me the solution.
0
Hello Sheshagiri,
Can you please verify that the taskhID field is included in the DataKeyNames of the corresponding table view?
http://demos.telerik.com/aspnet-ajax/grid/examples/data-binding/programmatic-hierarchy/defaultcs.aspx?#qsf-demo-source
Looking forward to your reply.
Regards,
Eyup
Telerik
Can you please verify that the taskhID field is included in the DataKeyNames of the corresponding table view?
http://demos.telerik.com/aspnet-ajax/grid/examples/data-binding/programmatic-hierarchy/defaultcs.aspx?#qsf-demo-source
Looking forward to your reply.
Regards,
Eyup
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
0
n/a
Top achievements
Rank 1
answered on 27 Sep 2019, 06:00 AM
Can you solved problem.
I have the same question.
this.RadGrid1.Columns.Count = 0
0
Hello,
Try using the RenderColumns collection of the MasterTableView instance to traverse the grid columns:
https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/how-to/Common/using-the--getitems-getcolumn-and-getcolumnsafe-methods#columns
I hope this will prove helpful. Feel free to give it a try and let me know if it works for you.
Regards,
Eyup
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.