473,387 Members | 2,436 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

ISSUES in Dynamic datagrid creation using asp .net(C# ) [Please suggest a way-out]

Hi there,
Iam trying to create a datagrid dynamically in asp .net (C#). It
contains a leftmost column with the check box and few data columns and
the last column is a hyperlink column. Please find the code attached
below.
The sorting, paging also doesnt work.
private void BuildDataGrid()
{
System.Web.UI.WebControls.DataGrid objDG2 = new
System.Web.UI.WebControls.DataGrid();
DataTable objDtTable = new DataTable();

int itemIndex =0;

objDAL.getStoredProcedureIntoDT("usp_GET_ALL_Users ",ref objDtTable);

objDG2.Columns.Clear();

objDG2.Width = Unit.Percentage(100);
objDG2.Height= 400;
objDG2.GridLines = GridLines.Both;
objDG2.CellPadding =1;
objDG2.ForeColor=System.Drawing.Color.Black;
objDG2.BackColor = System.Drawing.Color.Beige;
objDG2.AlternatingItemStyle.BackColor =
System.Drawing.Color.Gainsboro;
objDG2.HeaderStyle.BackColor = System.Drawing.Color.Brown;
objDG2.PageSize =5;
//
//
// objDG2.AutoGenerateColumns=false;
objDG2.AllowPaging =true;
objDG2.AllowSorting = true;
string columnName = objDtTable.Columns[itemIndex].ColumnName;

TemplateColumn objTC = new TemplateColumn();
objTC.HeaderTemplate = new
DataGridTemplate(ListItemType.Header,columnName);
objTC.ItemTemplate = new
DataGridTemplate(ListItemType.Item,columnName);

objDG2.Columns.Add(objTC);

objDG2.DataSource = objDtTable;
objDG2.DataBind();
plcDgCtl.Controls.Add(objDG2);
}

public class DataGridTemplate : System.Web.UI.Page,ITemplate
{
ListItemType templateType;
string columnName;
public DataGridTemplate(ListItemType type, string colname)
{
templateType = type;
columnName = colname;
}

public void InstantiateIn(System.Web.UI.Control container)
{
Literal lc = new Literal();

switch(templateType)
{
case ListItemType.Header:
lc.Text = "<B>" + columnName + "</B>";
container.Controls.Add(lc);
break;
case ListItemType.Item:
//lc.Text = "Item " + columnName;
CheckBox objChk = new CheckBox();
//objChk.ID = strId;
container.Controls.Add(objChk);
break;
case ListItemType.EditItem:
TextBox tb = new TextBox();
tb.Text = "";
container.Controls.Add(tb);
break;
case ListItemType.Footer:
lc.Text = "<I>" + columnName + "</I>";
container.Controls.Add(lc);
break;
}
}
}

Jun 1 '06 #1
0 1165

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: JP011 | last post by:
Hello I have hit a major road block when it comes to building my dynamic datagrid. To make a long story short I need a dynamic datagrid because my connection string could change and I need the...
1
by: CanoeGuy | last post by:
I have been trying for the last two weeks to display a dynamic DataGrid. The data that I'm pulling from a SQL Server DB will have whole columns that will be either NULL or 0. I want to display...
5
by: Tompa | last post by:
Hi, I would like to create images on the fly as a response to an http request. I can do this with PIL like this (file create_gif.py): from PIL import Image, ImageDraw print 'Status: 200 OK'...
1
by: Ramki | last post by:
hi guys, How to Add a Blank row in a datagrid without using dataset Please reply ASAP. Very urgent. Thanks inadvance.
2
by: charliewest | last post by:
I need to create textboxes in real-time, the actual number of which is determine by a result from a database query. I have been able to create the controls, and then add them to the ASPX page....
0
by: optimizeit | last post by:
What I am attempting to do is import an Excel Workbook and display the worksheets in a datagrid dynamically. I am very close to getting this to work. I have to this point successfully imported a...
1
by: mitramay | last post by:
I am creating a dynamic datagrid. The controls in some of the template columns will have to be generated based on the data contained in them (i.e. the data for that respective DataField column)....
0
by: cindy | last post by:
I have a dynamic datagrid. I have custom classes for the controls public class CreateEditItemTemplateDDL : ITemplate { DataTable dtBind; string strddlName; string strSelectedID; string...
2
by: jon | last post by:
I'm trying to write a block of code that can create an instance of a generic object, with the Type coming in as a dynamic string. It isn't working yet. Any advice how I can dynamically create the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.