Subscribe to Subscribers

Forums » .NET » ASP.NET »

Runtime template column in c# asp.net for GridView


Posted Date: 23 Nov 2009      Posted By:: akash a bhave     Member Level: Gold    Member Rank: 1125     Points: 1   Responses: 2



Hello everybody,
I want to add template column run-time. Here is my code.
Code.aspx.cs
public class cs1
{
private void Pageload()
{
if(!isPostBack)
{
DataTable dt = new DataTable();
DataColumn dcol;
grdDynamicMatrix.DataSource = dt.DefaultView;
grdDynamicMatrix.DataBind();

dcol = new DataColumn("chk1", typeof(System.String));
dt.Columns.Add(dcol);

sizeArray = size.Split(',');

for (int j = 0; j < sizeArray.Length-1; j++)
{
dcol = new DataColumn(sizeArray[j], typeof(System.String));
dt.Columns.Add(dcol);
}

int j1 = 0;
for (int nIndex = 0; nIndex < 10; nIndex++)
{
DataRow drow = dt.NewRow();
drow["chk1"] = "x";
while (j1 < sizeArray.Length - 1)
{
drow[sizeArray[j1]] = "Row-" + Convert.ToString((nIndex + 1));
j1++;
}
dt.Rows.Add(drow);
j1 = 0;
}


grdDynamicMatrix.DataSource = dt;
grdDynamicMatrix.DataBind();
}
}
}


code.aspx;

<asp:GridView ID="grdDynamicMatrix" runat="server">
</asp:GridView>




Responses

#446015    Author: Srikanth C      Member Level: Bronze      Member Rank: 0     Date: 23/Nov/2009   Rating: 2 out of 52 out of 5     Points: 2

refer this link http://www.codeproject.com/KB/aspnet/DynamicTemplateColumn.aspxyou there you can find step by step to add TemplateCloumn dynamically

 
#446188    Author: Manindra Kumar Upadhyay      Member Level: Gold      Member Rank: 184     Date: 23/Nov/2009   Rating: 2 out of 52 out of 5     Points: 2

try this,
http://www.codeproject.com/KB/webforms/ASPNET_DataGrid_creation.aspx
http://www.codeproject.com/KB/aspnet/create_template_columns.aspx


 
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Next : How to add and retrive dropdownlist control into viewstate ?
Previous : Bad Request (Invalid Hostname) Error
Return to Discussion Forum
Post New Message
Category:

Related Messages

Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Talk to Webmaster Tony John
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
2005 - 2013 All Rights Reserved.
.NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
Articles, tutorials and all other content offered here is for educational purpose only.
We are not associated with Microsoft or its partners.