473,672 Members | 2,640 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GridView with dropdown: asp.net 2.0

Hello,

I am using the following in a GridView. Currently, I am using a dropdown
that pulls the Name of the person, given the Employee ID. I am doing this
in both the ItemTemplate and the EditTemplate. This makes sense for the
EditTemplate becuase the user can then change the Employee using the
dropdown box. What I am trying to figure out is how to show the Employee
Name in the ItemTemplate without having to use a DropDownList Box. Is there
a way to reference the stored procedure (below) without using a
dropdownlist?
--
Thanks in advance,

sck10
<!-- Datasource: Dropdownlist: Contact Employee ID -->
<asp:SqlDataSou rce ID="dsEmployeeI DDLL" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:cnnSvctech %>"
SelectCommand=" sp_web_LabTrack " SelectCommandTy pe="StoredProce dure">
<SelectParamete rs>
<asp:Paramete r DefaultValue="F indContactDLL" Name="strParm01 "
Type="String" />
<asp:Paramete r DefaultValue="N oParameter" Name="strParm02 "
Type="String" />
<asp:Paramete r DefaultValue="N oParameter" Name="strParm03 "
Type="String" />
<asp:Paramete r DefaultValue="N oParameter" Name="strParm04 "
Type="String" />
</SelectParameter s>
</asp:SqlDataSour ce>

<asp:TemplateFi eld
HeaderText="Act ivity"
HeaderStyle-Font-Bold="true"
HeaderStyle-ForeColor="blac k"
ItemStyle-Width="70%"
ItemStyle-VerticalAlign=" Top" >
<ItemTemplate >
<asp:DropDownLi st id="ddlEmployee ID1" DataSourceID="d sEmployeeIDDLL"
Runat="Server"
DataTextField=" ContactName" DataValueField= "EmployeeID " SelectedValue=' <%#
Bind("EmployeeI D") %>'/>
<%--<asp:Label ID="lblEmployee ID" Text='<%# Eval("EmployeeI D") %>'
Runat="Server"/>--%>
</ItemTemplate>
<EditItemTempla te>
<asp:DropDownLi st id="ddlEmployee ID" DataSourceID="d sEmployeeIDDLL"
Runat="Server"
DataTextField=" ContactName" DataValueField= "EmployeeID " SelectedValue=' <%#
Bind("EmployeeI D") %>'/>
</EditItemTemplat e>
</asp:TemplateFie ld>
Dec 22 '05 #1
1 6487
Hi Sck10,

Welcome.
I think for your scenario, the DropDownList control is necessary because
we need it to pickup all the sub item list from DataBase and mapped the
curernt row's subitem index to it's Text property... However, if you do
need to avoid diplaying the text through DropDownList, we can consider put
another separate Label control in the TemplateColumn' s Itemtemplate
together with the DropDownList, and use the Label control's PreRender event
to set Text value from the DropDownList's Selected Text ..... (the
dropDownList's Visible is set to False...). below is some sample code
snippet:

<ItemTemplate >
<asp:DropDownLi st ID="lstCategory " runat="server"
DataSourceID="S qlDataSource2" DataTextField=" CategoryName"
DataValueField= "CategoryID " SelectedValue=' <%#
Bind("CategoryI D") %>' Visible="False" >
</asp:DropDownLis t>&nbsp;
<asp:Label ID="Label1" runat="server"
OnPreRender="La bel1_PreRender" Text="Label"></asp:Label>

</ItemTemplate>
</asp:TemplateFie ld>
protected void Label1_PreRende r(object sender, EventArgs e)
{
Label lbl = sender as Label;

DropDownList lst = lbl.NamingConta iner.FindContro l("lstCategory" )
as DropDownList;

if (lst != null)
{
lbl.Text = lst.SelectedIte m.Text;
}
}
Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


--------------------
| From: "sck10" <sc***@online.n ospam>
| Subject: GridView with dropdown: asp.net 2.0
| Date: Thu, 22 Dec 2005 17:43:45 -0600
| Lines: 55
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1506
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506
| Message-ID: <eZ************ **@tk2msftngp13 .phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: 189.202.185.135 .in-addr.arpa 135.185.202.189
| Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!tk 2msftngp13.phx. gbl
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:3666 82
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| Hello,
|
| I am using the following in a GridView. Currently, I am using a dropdown
| that pulls the Name of the person, given the Employee ID. I am doing this
| in both the ItemTemplate and the EditTemplate. This makes sense for the
| EditTemplate becuase the user can then change the Employee using the
| dropdown box. What I am trying to figure out is how to show the Employee
| Name in the ItemTemplate without having to use a DropDownList Box. Is
there
| a way to reference the stored procedure (below) without using a
| dropdownlist?
| --
| Thanks in advance,
|
| sck10
|
|
| <!-- Datasource: Dropdownlist: Contact Employee ID -->
| <asp:SqlDataSou rce ID="dsEmployeeI DDLL" runat="server"
| ConnectionStrin g="<%$ ConnectionStrin gs:cnnSvctech %>"
| SelectCommand=" sp_web_LabTrack " SelectCommandTy pe="StoredProce dure">
| <SelectParamete rs>
| <asp:Paramete r DefaultValue="F indContactDLL" Name="strParm01 "
| Type="String" />
| <asp:Paramete r DefaultValue="N oParameter" Name="strParm02 "
| Type="String" />
| <asp:Paramete r DefaultValue="N oParameter" Name="strParm03 "
| Type="String" />
| <asp:Paramete r DefaultValue="N oParameter" Name="strParm04 "
| Type="String" />
| </SelectParameter s>
| </asp:SqlDataSour ce>
|
| <asp:TemplateFi eld
| HeaderText="Act ivity"
| HeaderStyle-Font-Bold="true"
| HeaderStyle-ForeColor="blac k"
| ItemStyle-Width="70%"
| ItemStyle-VerticalAlign=" Top" >
| <ItemTemplate >
| <asp:DropDownLi st id="ddlEmployee ID1" DataSourceID="d sEmployeeIDDLL"
| Runat="Server"
| DataTextField=" ContactName" DataValueField= "EmployeeID " SelectedValue=' <%#
| Bind("EmployeeI D") %>'/>
| <%--<asp:Label ID="lblEmployee ID" Text='<%# Eval("EmployeeI D") %>'
| Runat="Server"/>--%>
| </ItemTemplate>
| <EditItemTempla te>
| <asp:DropDownLi st id="ddlEmployee ID" DataSourceID="d sEmployeeIDDLL"
| Runat="Server"
| DataTextField=" ContactName" DataValueField= "EmployeeID " SelectedValue=' <%#
| Bind("EmployeeI D") %>'/>
| </EditItemTemplat e>
| </asp:TemplateFie ld>
|
|
|

Dec 23 '05 #2

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

Similar topics

6
7069
by: tfsmag | last post by:
I have a Grid that I've set up to have two of the fields use dropdownlists while in edit mode. Now I can bind the data to the dropdownlists just fine. My problem is that the second dropdown depends on the first dropdown to pass a parameter to it. If I have a selectedvalue set to the second drop down, when i select a new value from the first drop down it gives me this error. "Databinding methods such as Eval(), XPath(), and Bind() can...
4
4482
by: P. Yanzick | last post by:
Hello, I've been playing with master/detail views as well as editing in the gridview, and I ran across a strange problem that I am not exactly sure where to go to try to solve. I have 2 tables, a table of cars (pretty basic, an ID, a description, and a Color ID) and a table of colors (Color ID, and a color description). I've added a gridview and a detailsview as I'm playing with both and how to get editing features to work the way I...
4
29529
by: Dabbler | last post by:
I have two tables I'm editing in a Gridview. The VANS table contains a key to the other LESSOR table. I would like to use a dropdown list to select the LessorId value while displaying the Lessor table's "Company" field as text. When I commit the edit I get error:Must declare the scalar variable "@LessorId". Also as a bonus question ;) I don't know how to set the selectedindex value in the dropdown list based on the LessorId value in the...
1
14309
by: CorporateCoder | last post by:
Hi, I am trying to bind the selected value of a databound dropdown box in a databound gridview control to the value being displayed in the template column the dropdown box has been added to. Both the grid and the dropdown box are retrieving and displaying data fine, I just cant bind the two together. I followed the instructions in the help document called 'Walkthrough: Displaying a Drop-Down List While Editing in the GridView Web...
3
2101
by: Advertis | last post by:
Is there a way to populate a dropdown in a GridView with the next x years? I am using a GridView to display data from a SQL table One of the fields is a Year. I want to have the dropdown list not only the year in the db field, but also the current year to the next x years. Any ideas?
1
7760
by: mitchman10 | last post by:
My Time table has TimeID,Employee,PayPeriod,ChargeCodeID,Hours My Chargecode table has ChargecodeID,c_Text I need an Editable datagrid that will show the TimeID,Employee,PayPeriod,C_Text in a label and hours, along with an edit linkbutton. When they click on edit, the edit button turns to Update Cancel TimeID stays read Only
1
9684
by: William Youngman | last post by:
I have a gridview displaying data and would like to use the AJAX dropdown extender so that when the user clicks on a record a dropdown menu will display providing the user with a menu of selections to choose from (yes much like the SharePoint 2007 dropdown menu). I'm having problems dynamically binding the 'TargetControlID' property of the extender control to the record label in the gridview. What I'm doing is - The label's text is the...
2
10290
by: William Youngman | last post by:
We are developing an application that presents data to the user in a gridview and we are using the dropdown extender to give the user a SharePoint 2007 type dropdown menu attached to the cells of a given column. We are also using another dropdown menu that the user can use to select data using another quesry using the SelectedIndex change method. Upon initial page load everything works fine and the user is presented with a SharePoint type menu....
3
2182
by: =?Utf-8?B?V2FubmFiZQ==?= | last post by:
I have a gridview that uses a sqldatasource. The rows of the gridview are editable. When the gridview is in edit mode, one of the columns is a dropdown. In testing the editing, I deleted the dropdown entry from one of the rows. So, when the gridview comes up, it shows nothing in the column where I deleted it. Then when I select to edit that same row, I get an error because I cannot select the value for the dropdown for a non-existing value....
3
311
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I have a gridview with several template columns and a few command button columns, column 1 and 2 are dropdown boxes, column 3 is a checkbox and column 4 is a text box, followed by command button columns. These are all for data entry and although I am populating the dropdown list boxes with an objectdatasource so the user can provide a selection, I am not binding the gridview to anything. The command buttons again are for the user to be...
0
8418
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,...
0
8844
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8638
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8696
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6254
isladogs
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...
0
5720
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();...
0
4438
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2836
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2089
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.