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;
}
} 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;
}
}
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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,...
|
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: 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...
|
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,...
| |