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

Help referencing ddl in ItemTemplate vs EditItemTemplate

I have a datagrid with a dropdownlist in it. As I understand it, the
ItemTemplate section represents the cell when not in edit mode and the
EditItemTemplate section represents the cell when in edit mode. For
simplicity let's call ddl in ItemTemplate section "ddl1" and the ddl in the
EditItemTemplate section "ddl2".

I am trying to set the SelectedIndex value for the ddl's. When not in edit
mode I can set set an object to ddl1 with no problem. Here's how I do it:

MyDdlObject = CType(e.Item.Cells(1).FindControl("ddl1"), DropDownList)

When I try it with ddl2 I get Nothing.

MyDdlObject = CType(e.Item.Cells(1).FindControl("ddl2"), DropDownList)

How can I access this ddl that is in the EditItemTemplate section?

Thanks!
Nov 18 '05 #1
2 1897
VB Programmer wrote:
I have a datagrid with a dropdownlist in it. As I understand it, the
ItemTemplate section represents the cell when not in edit mode and the
EditItemTemplate section represents the cell when in edit mode. For
simplicity let's call ddl in ItemTemplate section "ddl1" and the ddl in the
EditItemTemplate section "ddl2".

I am trying to set the SelectedIndex value for the ddl's. When not in edit
mode I can set set an object to ddl1 with no problem. Here's how I do it:

MyDdlObject = CType(e.Item.Cells(1).FindControl("ddl1"), DropDownList)

When I try it with ddl2 I get Nothing.

MyDdlObject = CType(e.Item.Cells(1).FindControl("ddl2"), DropDownList)

How can I access this ddl that is in the EditItemTemplate section?


Are you trying to do this while not in edit mode? If so, you can't,
since the edititem does not exist; the regular itemtemplate is the type
of item being used. If you were in edit mode, the second one looks like
it should work.

May I ask why you have a dropdown in regular (itemtemplate) and
edittemplate both? Normally you show a label in the itemtemplate, then
when the user wants to edit, you have your edititemtemplate with the
dropdown. If you really do need this, you'll need to bind one of the
dropdowns (whichever one applies) everytime the user switches between modes.

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Nov 18 '05 #2
Thanks for the response Craig. I will double check the 'edit mode' thing.

FYI: I have a disabled ddl in itemtemplate, so people know that in edit mode
it is a ddl. Just GUI preference. :)

How can I tell the current 'mode' I'm in? How can I set the current 'mode'?

Thanks!

"Craig Deelsnyder" <cdeelsny@NO_SPAM_4_MEyahoo.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
VB Programmer wrote:
I have a datagrid with a dropdownlist in it. As I understand it, the
ItemTemplate section represents the cell when not in edit mode and the
EditItemTemplate section represents the cell when in edit mode. For
simplicity let's call ddl in ItemTemplate section "ddl1" and the ddl in the EditItemTemplate section "ddl2".

I am trying to set the SelectedIndex value for the ddl's. When not in edit mode I can set set an object to ddl1 with no problem. Here's how I do it:
MyDdlObject = CType(e.Item.Cells(1).FindControl("ddl1"), DropDownList)
When I try it with ddl2 I get Nothing.

MyDdlObject = CType(e.Item.Cells(1).FindControl("ddl2"), DropDownList)
How can I access this ddl that is in the EditItemTemplate section?

Are you trying to do this while not in edit mode? If so, you can't,
since the edititem does not exist; the regular itemtemplate is the type
of item being used. If you were in edit mode, the second one looks like
it should work.

May I ask why you have a dropdown in regular (itemtemplate) and
edittemplate both? Normally you show a label in the itemtemplate, then
when the user wants to edit, you have your edititemtemplate with the
dropdown. If you really do need this, you'll need to bind one of the
dropdowns (whichever one applies) everytime the user switches between

modes.
--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET

Nov 18 '05 #3

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

Similar topics

2
by: VB Programmer | last post by:
I have a datagrid with a dropdownlist in it. As I understand it, the ItemTemplate section represents the cell when not in edit mode and the EditItemTemplate section represents the cell when in...
2
by: News | last post by:
Hi I need help to display and edit data in a data grid within a repeater. The code is below: Sub dgrdEvents_EditCommand(sender As Object, e As DataGridCommandEventArgs)...
6
by: Tim Meagher | last post by:
Can anyone help me figure out how to apply a stylesheet to a pushbutton defined in the asp:BoundColumn or asp:EditCommandColumn elements of a datagrid?
2
by: I am Sam | last post by:
Ok I set up a button column to delete an individual record. Nothing happens when I test it. Someone please help understand why. Below is the associated coding: DataGrid control: ...
7
by: ÀÏÆÅ»³ÔÐ5¸öÔ | last post by:
I want use dropdownlist contral in gridview but have trouble now mycode here: i'm very sorry for my poor english <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"...
0
by: ElGordo | last post by:
I've been searching all over and think I am close, but keep getting the error "Index out of range" when trying to reference a nested datagrid when an OnEditCommand event is raised. When the...
0
by: Chris | last post by:
I've been searching all over and think I am close, but keep getting the error "Index out of range" when trying to reference a nested datagrid when an OnEditCommand event is raised. When the...
0
by: Aws | last post by:
My crazy GridView !! I am using Visual Studio 2005, I have a problem with my GridView. I have one access .mdb table and when I update a record on the table EVERYTHING is perfect. I made a Web...
0
by: sonali | last post by:
I Have A Grid With Drop Down List As Template Column In Scrolling There Is some Problem Code Is As Follows: <style type="text/css"> .gridFixedHeader { background-color:white;...
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: 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: 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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...

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.