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

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:SqlDataSource ID="dsEmployeeIDDLL" runat="server"
ConnectionString="<%$ ConnectionStrings:cnnSvctech %>"
SelectCommand="sp_web_LabTrack" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter DefaultValue="FindContactDLL" Name="strParm01"
Type="String" />
<asp:Parameter DefaultValue="NoParameter" Name="strParm02"
Type="String" />
<asp:Parameter DefaultValue="NoParameter" Name="strParm03"
Type="String" />
<asp:Parameter DefaultValue="NoParameter" Name="strParm04"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>

<asp:TemplateField
HeaderText="Activity"
HeaderStyle-Font-Bold="true"
HeaderStyle-ForeColor="black"
ItemStyle-Width="70%"
ItemStyle-VerticalAlign="Top" >
<ItemTemplate>
<asp:DropDownList id="ddlEmployeeID1" DataSourceID="dsEmployeeIDDLL"
Runat="Server"
DataTextField="ContactName" DataValueField="EmployeeID" SelectedValue='<%#
Bind("EmployeeID") %>'/>
<%--<asp:Label ID="lblEmployeeID" Text='<%# Eval("EmployeeID") %>'
Runat="Server"/>--%>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList id="ddlEmployeeID" DataSourceID="dsEmployeeIDDLL"
Runat="Server"
DataTextField="ContactName" DataValueField="EmployeeID" SelectedValue='<%#
Bind("EmployeeID") %>'/>
</EditItemTemplate>
</asp:TemplateField>
Dec 22 '05 #1
1 6477
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:DropDownList ID="lstCategory" runat="server"
DataSourceID="SqlDataSource2" DataTextField="CategoryName"
DataValueField="CategoryID" SelectedValue='<%#
Bind("CategoryID") %>' Visible="False">
</asp:DropDownList>&nbsp;
<asp:Label ID="Label1" runat="server"
OnPreRender="Label1_PreRender" Text="Label"></asp:Label>

</ItemTemplate>
</asp:TemplateField>
protected void Label1_PreRender(object sender, EventArgs e)
{
Label lbl = sender as Label;

DropDownList lst = lbl.NamingContainer.FindControl("lstCategory")
as DropDownList;

if (lst != null)
{
lbl.Text = lst.SelectedItem.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.nospam>
| 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.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 189.202.185.135.in-addr.arpa 135.185.202.189
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msft ngp13.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:366682
| X-Tomcat-NG: microsoft.public.dotnet.framework.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:SqlDataSource ID="dsEmployeeIDDLL" runat="server"
| ConnectionString="<%$ ConnectionStrings:cnnSvctech %>"
| SelectCommand="sp_web_LabTrack" SelectCommandType="StoredProcedure">
| <SelectParameters>
| <asp:Parameter DefaultValue="FindContactDLL" Name="strParm01"
| Type="String" />
| <asp:Parameter DefaultValue="NoParameter" Name="strParm02"
| Type="String" />
| <asp:Parameter DefaultValue="NoParameter" Name="strParm03"
| Type="String" />
| <asp:Parameter DefaultValue="NoParameter" Name="strParm04"
| Type="String" />
| </SelectParameters>
| </asp:SqlDataSource>
|
| <asp:TemplateField
| HeaderText="Activity"
| HeaderStyle-Font-Bold="true"
| HeaderStyle-ForeColor="black"
| ItemStyle-Width="70%"
| ItemStyle-VerticalAlign="Top" >
| <ItemTemplate>
| <asp:DropDownList id="ddlEmployeeID1" DataSourceID="dsEmployeeIDDLL"
| Runat="Server"
| DataTextField="ContactName" DataValueField="EmployeeID" SelectedValue='<%#
| Bind("EmployeeID") %>'/>
| <%--<asp:Label ID="lblEmployeeID" Text='<%# Eval("EmployeeID") %>'
| Runat="Server"/>--%>
| </ItemTemplate>
| <EditItemTemplate>
| <asp:DropDownList id="ddlEmployeeID" DataSourceID="dsEmployeeIDDLL"
| Runat="Server"
| DataTextField="ContactName" DataValueField="EmployeeID" SelectedValue='<%#
| Bind("EmployeeID") %>'/>
| </EditItemTemplate>
| </asp:TemplateField>
|
|
|

Dec 23 '05 #2

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

Similar topics

6
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...
4
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...
4
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...
1
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. ...
3
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...
1
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...
1
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...
2
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...
3
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...
3
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...
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
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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: 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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.