473,406 Members | 2,293 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,406 software developers and data experts.

Datagrid binding to Itemplate Dropdown box

I'm trying to bind to a Template Item that I created and fill the dropdown
with a value from the datagrid DataSet. However, if the value is "", then I
want to Insert a "[Select One]" option to the list. I'm trying to do this
as the binding takes place, but it's not working. The extra option is not
added. Any advice?

The goal: do in-line editing inside the datagrid without adding code to the
ASPX page. I want it all in the code behind. It's got to be possible, I
just haven't figured it out yet.... The labels and textboxes are working
fine, but the DropDownList box is giving me headaches.

Andrea
PS: Here's the code in the custom class which inherits ITemplate.

public override void InstantiateIn(Control container)

{

// Bind a string to the event

DropDownList cboResult = new DropDownList();

if (this.ControlID != null)

cboResult.ID = this.ControlID;

cboResult.DataSource = this.mobjDataSource;

cboResult.DataTextField = this.mstrDataTextField;

cboResult.DataValueField = this.mstrDataValueField;

cboResult.DataBinding += new EventHandler(this.BindData);

container.Controls.Add(cboResult);

}

protected void BindData(object sender, System.EventArgs e)

{

if (!Common.Global.isNothing(this.DataField))

{

DropDownList cboSender = (DropDownList) sender;

DataGridItem container = (DataGridItem) cboSender.NamingContainer;

string strDataFieldValue =
((System.Data.DataRowView)container.DataItem)[this.DataField].ToString();

cboSender.Items.Insert(0, new ListItem("[Select One]", "")); //This is
the line that isn't working

// BTW, if I leave this line out and the value of strDataFieldValue = "", I
get an error b/c the value "" doesn't exist in the DataSet.

cboSender.SelectedValue = strDataFieldValue;

cboSender = null;

}

}
Nov 18 '05 #1
1 2386
For anyone else trying to find the answer to this question...

http://www.codeproject.com/aspnet/AS...291#xx890291xx

I asked the author and he responded. My in-line editing is working now!
YAY!

Andrea

"Andrea Williams" <an*******@hotmailIHATESPAM.com> wrote in message
news:#g**************@tk2msftngp13.phx.gbl...
I'm trying to bind to a Template Item that I created and fill the dropdown
with a value from the datagrid DataSet. However, if the value is "", then I want to Insert a "[Select One]" option to the list. I'm trying to do this
as the binding takes place, but it's not working. The extra option is not
added. Any advice?

The goal: do in-line editing inside the datagrid without adding code to the ASPX page. I want it all in the code behind. It's got to be possible, I
just haven't figured it out yet.... The labels and textboxes are working
fine, but the DropDownList box is giving me headaches.

Andrea
PS: Here's the code in the custom class which inherits ITemplate.

public override void InstantiateIn(Control container)

{

// Bind a string to the event

DropDownList cboResult = new DropDownList();

if (this.ControlID != null)

cboResult.ID = this.ControlID;

cboResult.DataSource = this.mobjDataSource;

cboResult.DataTextField = this.mstrDataTextField;

cboResult.DataValueField = this.mstrDataValueField;

cboResult.DataBinding += new EventHandler(this.BindData);

container.Controls.Add(cboResult);

}

protected void BindData(object sender, System.EventArgs e)

{

if (!Common.Global.isNothing(this.DataField))

{

DropDownList cboSender = (DropDownList) sender;

DataGridItem container = (DataGridItem) cboSender.NamingContainer;

string strDataFieldValue =
((System.Data.DataRowView)container.DataItem)[this.DataField].ToString();

cboSender.Items.Insert(0, new ListItem("[Select One]", "")); //This is
the line that isn't working

// BTW, if I leave this line out and the value of strDataFieldValue = "", I get an error b/c the value "" doesn't exist in the DataSet.

cboSender.SelectedValue = strDataFieldValue;

cboSender = null;

}

}

Nov 18 '05 #2

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

Similar topics

0
by: Kilic Beg via .NET 247 | last post by:
Hi, I am having trouble adding a dropdown to DataGrid at runtime. I create all boundColumns and the TemplateColumn for the dropdown at runtime. The dropdown has a different datasource then the...
6
by: rodchar | last post by:
Hey all, I have an array of data rows that when I bind it to a datagrid it shows all those extra rows in addition to my fields. How do I hide those fields? I tried using the TableStyles...
3
by: Phil | last post by:
Using C#, I am building my datagrid in my code behind due to the need to dynamically build the columns. In my Code I use an array to accomplish this and I also use an if statement to determine if...
0
by: mike | last post by:
Hi there: I've read an excellent "how to"-article by Microsoft (no. 306227) - partly cited cited at the end of this email). I have implemented the code related to the part "How to Add a...
1
by: sianan | last post by:
I tried to use the following example, to add a checkbox column to a DataGrid in an ASP.NET application: http://www.codeproject.com/aspnet/datagridcheckbox.asp For some reason, I simply CAN'T get...
2
by: Javier | last post by:
Hi Everyone, I have a dynamic checkbox in a datagrid that uses the ITemplate interface and has the checkchanged event wired up. When the checkbox is checked, the event event handler that...
3
by: Fao, Sean | last post by:
I have a DataGrid that I'm adding CheckBox controls to at runtime (in the code behind) and I'm not sure if I'm doing it correctly. First of all, I noticed that the MyDataGrid.Columns.Add() method...
2
by: Peter | last post by:
ASP.NET 2003 In the DataGrid how do I select current cell value in the dropdown box when I click on the edit link, currently when I click on the edit link in the DataGrid the dropdown box...
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...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.