DataGrid - DropDownList (How do I set this value from a value in the datagrid?)


 I'd like to set the value of a DropDownList based on a value of another field in the DataGrid.

These values are from different <columns>.

The first value shows up just fine in the "BoundColumn".

But, the one I want to set in the TemplateColumn isn't working.

Can someone take a look at my code snippet and see what I'm doing wrong?


The Control I'm trying to set is called "ddlBenchStart".

I'm trying to get the value from the "BenchStart" column.

The values in "BenchStart" would be "Bench" or "Start".


I'd tried setting the "DataTextField" and "DataValueField" properties for the "ddlBenchStart" control.

But, this doesn't work.  So, I'm assuming I'm doing something wrong.

A little guidance would be appreciated.

Here's the snippet:



    <form ID="frmLineUpEntry" runat="Server">
        <asp:DataGrid ID="dtgPlayers" DataKeyField="PlayerID" AutoGenerateColumns="False" BackColor="#053C1D" GridLines="Both" CellPadding="5" HeaderStyle-BackColor="black" HeaderStyle-ForeColor="Orange" HeaderStyle-Font-Bold="True"  runat="Server">
                <asp:BoundColumn DataField="PlayerID" HeaderText ="ID" Visible="False"  />
                <asp:BoundColumn DataField="Pos" HeaderText ="Pos"  />
                <asp:BoundColumn DataField="BenchStart" HeaderText ="Bench/Start" />
                <asp:TemplateColumn HeaderText="Bench/Start">
                            <asp:DropDownList ID="ddlBenchStart" DataTextField="BenchStart" DataValueField="BenchStart" runat="Server">
                                <asp:ListItem Value="Start" Text ="Start" />
                                <asp:ListItem Value="Bench" Text ="Bench" />
                <asp:BoundColumn DataField="PlayerName" HeaderText ="Player Name" ItemStyle-HorizontalAlign="Left"/>
                <asp:BoundColumn DataField="Team" HeaderText ="Team"  /> 
                <asp:BoundColumn DataField="ByeWeek" HeaderText ="Bye"  /> 




8/29/2006 5:22:36 PM 72751 articles. 3 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 51


You would to use ItemDataBound event to DataGrid control. And set value to your DropDownList control to every ItemDataGrid.

Good Coding!

Javier Luna


from Villa El Salvador for world!
8/31/2006 5:35:05 PM

Similar Artilces:

how to accessing values and set values for a controls that is inside a datagrid
hi this is chandra mohan working as software engineer . here i am having problem with accessing valuse and setting values for controls inside a datagrid. actually i am having datagrid and in this grid i am having item templates of one dropdwon list and text box. i having one Reset link buttion out side the grid(that is in the form) by clicking this Reset Link buttion it should invokes the javascript function and in that function it should set all textboxes of datagrid to  .. txtActionVal.readOnly = true;   txtActionVal.Value ="";and dropdownlist to  dropdownlist...

select the row of the datagrid whose value is same as one of the value of row of datagrid
hellow all,  I have a datagrid which is bound to the ordertable,so all the orderdetails are shown on the page load. but my requirement is that,i have a textbox and a search button,when the user enter the order number in the text box and click on the search button the datagrid should show that record whose order number is entered by the user n most imp that the record may be in the 65th or 34th row of the datagrid,i wants to put it in the first row. how to do it. If there's a reason you can't filter down to just the one row, you'll have to come up with some paging algorithm that wil...

Setting the value of a checkbox by the value of another checkbox in a DataGrid
If a user sets a checkbox to true I want it to automatically set the value of another checkbox in the datagrid to be true.  If you can tell by the code below, once a users selects checkbox 13 I use an onClick even to call a javascript. I don't believe that UpdateCheckBox.ClientID is actually being passed. I get an error in my javascript (posted below) that the object is null. Can anyone tell me the correct way to access the id of the checkbox so that I may use the object in my javascript? <asp:templatecolumn headertext="Month 14">    <itemte...

DataGrid not updating
Ok this is driving me nuts!I have a data grid and most of it's working - except the Update button. When I edit, it goes into edit mode correctly, but when I click update, it ignores my changes and reverts back to what it was. Here's my code: <form runat="server"> <div id="divBody">  <h2>Modify Sections</h2>  <asp:DataGrid id="dgSections" runat="server"    DataKeyField="ID"   AutoGenerateColumns="false"   Width="100%"   GridLines="None"   HeaderStyle-CssClass="ListHe...

Datagrid(.net 1.1) to GridView(.net 2.0) and using the RowUpdating event how to extract the values from the controls.
Ok  This is the settings: I use a Viewgrid with only itemtemplate colums for example. <asp:TemplateField HeaderText="Test"><ItemTemplate><asp:Label id="LBL_Test" text='<%# DataBinder.Eval(Container.DataItem, "Test1") %>' runat="server" meta:resourcekey="LBL_TestResource1"></asp:Label></font></ItemTemplate> <EditItemTemplate><asp:TextBox ID="HDN_Test" Text='<%# DataBinder.Eval(Container.DataItem, "Test1") %>' Runat="server" meta:resourcekey="HDN_TestResource1" /></EditItemTemplate></asp:TemplateField>  The ...

How to set a string value from a label control within a datagrid?
Hi I have been having a lot of trouble with this for some reason, it seems like it would be a simple task yet for some wierd reason it isn't. I have a datagrid named DataGrid1 that is dynamically created using code-behind language c#. I'm using 4 template columns that have label controls which hold the bound data from the sql database. I also have a buttoncolumn that initiates a itemcommand using the CommandName "Select". I then have a table that is also dynamically created in the same code-behind file that will be the container for the so called shopping cart. to add columns to th...

nested datagrid--trouble using value from parent datagrid to populate nested datagrid
Hi all,I am having trouble nesting two datagrids.  The master one populates correctly.  The other one gets a value from the master datagrid and should populate based on it's value.  It's value determines whether the customer ordered a package deal...the child datagrid would list out all the items in the package deal (something like the below, the green is the master, the yellow is the child stuff):family package deal 1    1 movie    2 buckets of popcorn    4 small sodas    1 pk sour patch kidsI am getting this error:T...

Setting the text value of a textbox control in a datagrid -without- databinding.
Hello,I'm currently having trouble setting the text value of a textbox control within a datagrid without using the databind technique.  I've never had to do this before, I've only had to databind and read values so I have no idea how to do this.  The method I use to read values doesn't allow me to set them at all unfortunately.I've found a very sketchy work around using javascript and images but this would cause a lot of problems and having a clean cut way through this (since it's only one line of code giving trouble) would result in a much more stable and understandable project.Th...

new to .net, need help setting db values from checkbox's then retrieving value to a label control
Hi, Being new to i know this possible i just can't quite get it right!  I need a page with 5 checkbox's that when submitted sets the bit values in DB fields to checked. Then i need another page that retrieves the records of the checkboxes, but instead of having the db pre-set checkboxes on the second page i want it to turn on label web controls depending on if the check box is set.. I hope that makes sense?!! Can anyone point me in the right direction or to a suitable tutorial? Thanks in advance Ben Excellent article here.

Get the value of undisplayed value from datagrid..
Can anyone please help me. I am using a datagrid and specified the "DataKeyField" as "cts_id1". And i am not getting all the columns from the datasource. So, i have "AutoGenerateColumns" = false. I am also using a EditCommandColumn. When i click on the update, i want to get the value of "cts_id1". How can i get the value for which i am not displaying on the screen. But this field is there in the dataset. For the columns that i am displaying, i am using ctype(e.item.cells(0).controls(0), textbox).text This is giving me correct results. But i ...

Recalculating values in datagrid with values from a textbox
Hello,I have a datagrid which is databound.Users enter the data into the webform which is saved into the database and this data is later retrieved and viewed in a Datagrid. As of now about 200 records have been created and they are all visible in the datagrid.The next step is that on the datagrid page, there is a textbox to enter monthly exchange rate on the top of the page i.e. outside the datagrid, users will enter a value in this textbox and based on that value 3 columns in the datagrid need to be enter EOMRate: ____________ (this is a textbox) |V   This is...

Edit Values of a DataGrid Inside a DataGrid
Hi, I have a DataGrid that does the following: a) Displays Current Projetcs based on the user b) When the user click on Edit, theres another datagrid on a template colunm that dysplays the work history how Can I perform the same Edit, Cancel, Update Functions on the child datagrid? Have you considered using third party controls? Have a look at Hierargrid. If you want to stick with grid in a grid implementation, you have to hook the Edit/Cancel/Update event handlers to the inner grid in the html etcBug [MCSD]...

Hilight a cell value in a Datagrid depending on its value
Hi, My datagrid contains the several "Price" columns, I want the cell containing the lowest price in each rows to be hilighted or get a different color background. How can I acheive that? Thanks. Best regards. I accomplish this by using a template column and a helper function. My datagrid has columns for both Target and Availability. Template column for availability looks like this: <asp:TemplateColumn HeaderText="12 Week Rolling"> <ItemStyle Width="50px" Wrap="False"></ItemStyle> <ItemTemplate&...

Recalculating values in a datagrid with values fom textbox
Hello,I have a datagrid which is databound.Users enter the data into the webform which is saved into the database and this data is later retrieved and viewed in a Datagrid. As of now about 200 records have been created and they are all visible in the datagrid.The next step is that on the datagrid page, there is a textbox to enter monthly exchange rate on the top of the page i.e. outside the datagrid, users will enter a value in this textbox and based on that value 3 columns in the datagrid need to be enter EOMRate: ____________ (this is a textbox)|V This is the datagrid_____...

Take a value from datagrid and open a new datagrid
I have two sql tables that connect with bid keyfield. So i want to see at first the first table in my datagrid and based ot the user's selection a new page will open with the new table view in a datagrid. What is the est way to do this? Can i present in my datagrid a field as a hyperlink instead of an edit column? Sure, you can use a link column. You could pass the value to the querystring of the hyperlink and check for that value in the new page. Should be simple. You may also consider a nested datagrid, if the 2nd datagrid doesnt contain that much information. Hope that helps.Sonu ...

Web resources about - DataGrid - DropDownList (How do I set this value from a value in the datagrid?) -

Tag Synonyms - Stack Overflow
Q&A for professional and enthusiast programmers

Accidental entities - what about the UI?
This post is a follow-up to my previous blog post " Accidental entities - you don't need that identity ". In that post, we followed a consultant ...

Flash Builder Plug-in for SAP Netweaver Gateway - Adobe Labs
Search Navigation Labs Home Wiki Home Technologies Alchemy Blueprint Camera Profiles and DNG Profile Editor Cirrus ColdFusion 10 DNG Codec Fireworks ...

Air Astana - Join Now
Thank you for considering membership of Nomad Club – Kazakhstan’s first Frequent Flyer Program. You could soon be on your way to earning free ...

Languages -> C# Articles, Tutorials, Examples: ASP Alliance
.NET,ASP,ASP.NET,SQL,XML,HTML,ADO,ADO.NET,JavaScript,JScript,CSharp,VBScript and VB tutorials from AspAlliance.

Blog - Avisra
Avisra Web Development Home Blog Services Contact The Blog Latest Module Builder: How can we make it better? Sitefinity by Chris on July 2, 2013 ...

Online Booking Tool Support
This Online Booking Tool Support page might help you as you navigate through the process of booking travel through your OBT provided by CWT. ...

@Html and beyond
... ); } return string .Format( “{0}{1}” , me.Member.Name, id); } The Html building methods are quite simple. Building a dropdownlist for a ...

Top Ranked Articles
Top Ranked Articles - Free source code and tutorials for Software developers and Architects.; Updated: 23 Feb 2013

Unit Testing DateTime.Now Without Isolation
public virtual void SeedWithYearsSince(DropDownList list, int year){ for (int index = year; index

Resources last updated: 12/15/2015 4:08:47 AM