473,385 Members | 1,486 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,385 software developers and data experts.

Dynamic control creation in datagrid based on data in that column

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). For example, if I

have a column called Available, the possible values for it are Yes or
No. In case it is "Yes" I need a label in that column and in case it is

"No" I need a hyperlink. Pls help.

Sep 20 '06 #1
1 2016
add event handler to your datagrid ItemDatabound event as below

private void dg_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)

{

if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)

{

// get your data using your datasource for the selected index( ie,
e.Item.ItemIndex)

bool bYes = false; //Check for yes or no value here

if(bYes)

{
Label lbl = new Label();

lbl.Text = "Yes";

e.Item.Cells[0].Controls.Add(lbl); // I assume your template column is first
column , if not adjust your cell index accordingly

}

else

{

HyperLink link = new HyperLink ();

link .Text= "No";

link.NavigateUrl = "";/* set your url here */

e.Item.Cells[0].Controls.Add(link);

}

}

}

<mi******@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
>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). For example, if I

have a column called Available, the possible values for it are Yes or
No. In case it is "Yes" I need a label in that column and in case it is

"No" I need a hyperlink. Pls help.

Sep 22 '06 #2

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

Similar topics

8
by: Ashish Shridharan | last post by:
Hi All I have been trying to add a control to the header cell of a datagrid on my ASP.NET page. These controls are defined in the HTML as ASP.NET web controls. They are being added into the...
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: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
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...
7
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...
2
by: Tumurbaatar S. | last post by:
I dynamically add columns to DataGrid as described in MSDN articles "Top Questions about the DataGrid Web Server Control" and "Creating Web Server Control Templates Programmatically". The columns...
0
by: gokulrajad | last post by:
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...
0
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: JamesOo | last post by:
I have the code below, but I need to make it searchable in query table, below code only allowed seach the table which in show mdb only. (i.e. have 3 table, but only can search either one only,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.