From VS.NET 03 AND VB.NET
I added a dropdown list to a data grid control in response to the
EditCommand event to force users to pick values from a list and not
type them in. I used the following code:
'Hide the existing txt box
Dim txt As TextBox
txt = CType(e.Item.Ce lls(0).Controls (0), TextBox)
txt.Visible = False
'display a ddl instead
Dim ds As New DataSet
ds = dbCalls.GetData
Dim ddl As New DropDownList
ddl.ID = "myID"
ddl.DataSource = ds
ddl.DataTextFie ld = "myTxt"
ddl.DataValueFi eld = "myID"
ddl.DataBind()
ddl.Attributes. Add("class", "myCSS")
e.Item.Cells(0) .Controls.Add(d dl)
This works great (everything displays as intended in the UI).
However, when I code the UpdateCommand I cannot find the DropDownList
control I created above. When I debug and add a watch for
e.Item.Cells(0) it only shows a single control
(e.Item.Cells(0 ).controls(0) which is the text box). How can I
reference the DropDownList control? I am using the following code:
Dim ddlMaintCatID As DropDownList
ddlMaintCatID = CType(e.Item.Ce lls(0).Controls (X), DropDownList)
For X i tried the following vales (0 and 1). For 0 I get and invalid
cast error becuase controls(0) is a text box and for 1 I get an index
out of range error.
What am I missing???
thanks in advance for your time and assistance.
Scott 2 1776
ddlMaintCatID = CType(e.Item.Ce lls(0).FindCont rol("myID"), DropDownList)
the above will work if you used
ddl.ID = "myID" and "myID" is a string, if it is the unique DB id then you
will have to substitue something to determine the currect ID (use a hidden
column and grab the text property or something)
"mystical_potat o" <He********@Fin gDie.Now> wrote in message
news:27******** *************** *********@4ax.c om... From VS.NET 03 AND VB.NET
I added a dropdown list to a data grid control in response to the EditCommand event to force users to pick values from a list and not type them in. I used the following code:
'Hide the existing txt box Dim txt As TextBox txt = CType(e.Item.Ce lls(0).Controls (0), TextBox) txt.Visible = False
'display a ddl instead Dim ds As New DataSet ds = dbCalls.GetData Dim ddl As New DropDownList ddl.ID = "myID" ddl.DataSource = ds ddl.DataTextFie ld = "myTxt" ddl.DataValueFi eld = "myID" ddl.DataBind() ddl.Attributes. Add("class", "myCSS") e.Item.Cells(0) .Controls.Add(d dl)
This works great (everything displays as intended in the UI). However, when I code the UpdateCommand I cannot find the DropDownList control I created above. When I debug and add a watch for e.Item.Cells(0) it only shows a single control (e.Item.Cells(0 ).controls(0) which is the text box). How can I reference the DropDownList control? I am using the following code:
Dim ddlMaintCatID As DropDownList ddlMaintCatID = CType(e.Item.Ce lls(0).Controls (X), DropDownList)
For X i tried the following vales (0 and 1). For 0 I get and invalid cast error becuase controls(0) is a text box and for 1 I get an index out of range error.
What am I missing???
thanks in advance for your time and assistance. Scott
Hi Potato:
I have some articles with C# source that might help. They talk about
the basics of using FindControl and using DropDownLists in a grid.
In Search Of ASP.NET controls http://odetocode.com/116.aspx
Embedding DropDownList Controls In A Grid http://odetocode.com/Articles/231.aspx
HTH,
--
Scott http://www.OdeToCode.com
On Tue, 07 Sep 2004 14:37:16 GMT, mystical_potato
<He********@Fin gDie.Now> wrote: From VS.NET 03 AND VB.NET
I added a dropdown list to a data grid control in response to the EditCommand event to force users to pick values from a list and not type them in. I used the following code:
'Hide the existing txt box Dim txt As TextBox txt = CType(e.Item.Ce lls(0).Controls (0), TextBox) txt.Visible = False
'display a ddl instead Dim ds As New DataSet ds = dbCalls.GetData Dim ddl As New DropDownList ddl.ID = "myID" ddl.DataSource = ds ddl.DataTextFie ld = "myTxt" ddl.DataValueFi eld = "myID" ddl.DataBind() ddl.Attributes. Add("class", "myCSS") e.Item.Cells(0) .Controls.Add(d dl)
This works great (everything displays as intended in the UI). However, when I code the UpdateCommand I cannot find the DropDownList control I created above. When I debug and add a watch for e.Item.Cells(0 ) it only shows a single control (e.Item.Cells( 0).controls(0) which is the text box). How can I reference the DropDownList control? I am using the following code:
Dim ddlMaintCatID As DropDownList ddlMaintCatI D = CType(e.Item.Ce lls(0).Controls (X), DropDownList)
For X i tried the following vales (0 and 1). For 0 I get and invalid cast error becuase controls(0) is a text box and for 1 I get an index out of range error.
What am I missing???
thanks in advance for your time and assistance. Scott This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Peter |
last post by:
I have an ASP.NET form written in C#, on this form I have few controls and a DataGrid control, under the DataGrid control I have few more controls. The DataGrid defaults to display 10 items.
When there are less than 10 items in the DataGrid there is an empty space between the DataGrid and the controls underneath the DataGrid, my question is how can get the controls underneath the DataGrid to move up dynamically depending on the size of the...
|
by: bill yeager |
last post by:
I did some more debugging and found the following:
1) I placed the following code in the button event just
to see if I could cycle thru the datagrid control
collection:
<code>
Dim strhello As String
Dim myDataListItem As DataListItem
Dim myDatagridItem As DataGridItem
Dim myCheckBox As CheckBox
|
by: Daniel Walzenbach |
last post by:
Hi,
I want to display a Label in a DataGrid according to some condition. I therefore check whether the condition is true in the ItemDateBound EventHandler of the DataGrid. Unfortunately the conversion is extremely costly in performance. Does anybody know how I could set the label (of the whole content of the TableCell) to .Visible = False without converting e.Item.Controls(2) to a System.Web.UI.WebControls.Label?
|
by: 2obvious |
last post by:
I have a DataGrid containing a TextBox control and a CustomValidator
in each row. The CustomValidator fires a function that compares all
TextBoxes for equality. The algorithm for comparison is
straightforward:
*PSEUDOCODE*
for i=1 thru ( Container.Length-1 )
for j=i+1 thru ( Container.Length-1 )
if ( TextBox==TextBox )
|
by: KatB |
last post by:
Hi, in order to format my web page, I'm starting to use Flow layout so
using html tables to space out controls, etc. When using grid layout,
the following worked when it was just a datagrid. I know I need to
somehow refer to the datagrid within the html table cell, but can't
figure out how.
THANKS!
Public Sub dgConfirmOrder_ItemDataBound(ByVal sender As System.Object,
ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles
| |
by: Lyners |
last post by:
I have a table within a cell of a datagrid. I am doing updates without
postback to the server using Javascript. I have everything working, except
referencing a table within the datagrid cell.
Here is my datagrid code for the cell;
<asp:TemplateColumn HeaderText="3Fields" ItemStyle-Font-Size="8"
SortExpression="Field1 ASC" ItemStyle-Font-Name="Verdana">
<ItemTemplate>
<table border="0">
<tr>
|
by: tjonsek |
last post by:
am working on code that will allow users to update data within the
datagrid. I have come across a few problems, some of them I have been
able to work out, but this last one is giving me trouble.
When a user clicks the edit button, I get an error 'Specified Cast Not
Valid'.
The code that generates the error is:
Dim strCompleted As String = CType(e.Item.Cells(6).Controls(1),
TextBox).Text
|
by: Arpan |
last post by:
Consider the following code which retrieves data from a SQL Server 2005
DB table & displays it in a DataGrid:
<script runat="server">
Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
Dim dSet As DataSet
Dim sqlConn As SqlConnection
Dim sqlDapter As SqlDataAdapter
sqlConn = New SqlConnection("Data Source=AD\SQLEXPRESS;Initial
|
by: DanG |
last post by:
Hi
I used to have an ImageButton in my datagrid, and referenced the
control in the javascript with:
var fld = document.getElementById('datagrid__ctl2_btnEdit');
alert(fld); //returns "" >Good
I changed the ImageButton to a LinkButton, but the javascript doesn't
work anymore.
var fld = document.getElementById('datagrid__ctl2_btnEdit'); //Same as
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |