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

Dropdownlist in gridview

How can i add dropdownlist box in gridview.......such that after selecting perticular item from dropdownlist box it get updated in database......using edititemtemplate field......
Apr 2 '07 #1
10 11001
kenobewan
4,871 Expert 4TB
Welcome to the site. Please provide more information and describe your problem clearly. Thanks.
Apr 2 '07 #2
gomzi
304 100+
thats easy man!
just add the dropdown box in an itemtemplate inside a templatefield.

then in vb,
in gridview rowcommand,
get the value of the selected dropdown box by,
ctype(me.gridview.rows(the number of the selected row in gridview).findcontrol("yourdropdownbox"),dropdownl ist).selectedvalue
Apr 2 '07 #3
thats easy man!
just add the dropdown box in an itemtemplate inside a templatefield.

then in vb,
in gridview rowcommand,
get the value of the selected dropdown box by,
ctype(me.gridview.rows(the number of the selected row in gridview).findcontrol("yourdropdownbox"),dropdownl ist).selectedvalue

Thanks for helping me...But i still have an problem that, how i can get the number of selected row in gridview .....I tried using Gridview.editIndex property but it give me negative index ..........
Actually what i have to do is after clicking edit button in gridview i have to add record of dropdownlist and textbox which i used in <asp:template field> in database......After clicking update button the record of both field should get added in database according to their id, which was already in gridveiw.....

To Make clear.... I have follwing filleds.
ID DROPDOWN TEXTBOX edit
.
,
Id was generated using select comman of gridview ,,but dropdown list is added using templatefield.........therefor i have to update rec of dropdown and txtbox after clicking edit button..
Apr 3 '07 #4
gomzi
304 100+
Thanks for helping me...But i still have an problem that, how i can get the number of selected row in gridview .....I tried using Gridview.editIndex property but it give me negative index ..........
Actually what i have to do is after clicking edit button in gridview i have to add record of dropdownlist and textbox which i used in <asp:template field> in database......After clicking update button the record of both field should get added in database according to their id, which was already in gridveiw.....

To Make clear.... I have follwing filleds.
ID DROPDOWN TEXTBOX edit
.
,
Id was generated using select comman of gridview ,,but dropdown list is added using templatefield.........therefor i have to update rec of dropdown and txtbox after clicking edit button..

Not able to get you 100%. but i guess that you are having problems in finding the row number.
I understand that you are retrieving an id column through your select command,
so in the edit button use the "commandname" property to specify the id and then retrieve the id in the gridview rowcommand through e.commandname

then after you retrieve the id, run a loop to get the row number.
Apr 3 '07 #5
Not able to get you 100%. but i guess that you are having problems in finding the row number.
I understand that you are retrieving an id column through your select command,
so in the edit button use the "commandname" property to specify the id and then retrieve the id in the gridview rowcommand through e.commandname

then after you retrieve the id, run a loop to get the row number.
Thanxs Gomzi,
i find the solution using ur previous post.....i added select cmd butoon in gridview(it is added using gridview enable selection property true), then onselectchanged method i retrieve the id, dropdownlist selected item and textbox text....... i have taken button which will save this 3 filds in database using store proc.... but the problem is i have to first select item from dropdown list box then i have to click select button then i have to click on save button .

What i have to do is after selecting select button i have to retrieve all 3 fields then after save btton click i have to save into database...
Apr 4 '07 #6
gomzi
304 100+
Thanxs Gomzi,
i find the solution using ur previous post.....i added select cmd butoon in gridview(it is added using gridview enable selection property true), then onselectchanged method i retrieve the id, dropdownlist selected item and textbox text....... i have taken button which will save this 3 filds in database using store proc.... but the problem is i have to first select item from dropdown list box then i have to click select button then i have to click on save button .

What i have to do is after selecting select button i have to retrieve all 3 fields then after save btton click i have to save into database...

Looking at the functionality that you want to achieve, i think that there is no need for you to add a select command button.

just place the dropdownlist and textbox in the templatefields and use a linkbutton (placed in a templatefield) for saving.(<asp:linkbuton commandname='<%# DataBinder.Eval(Container.DataItem,"Id") %>' > ...place the other necessary attributes)

now, when this linkbutton is clicked,your rowcommand will be called, in which you can get the dropdownlist and textbox's value through the method that i specified two posts back.
Apr 4 '07 #7
Looking at the functionality that you want to achieve, i think that there is no need for you to add a select command button.

just place the dropdownlist and textbox in the templatefields and use a linkbutton (placed in a templatefield) for saving.(<asp:linkbuton commandname='<%# DataBinder.Eval(Container.DataItem,"Id") %>' > ...place the other necessary attributes)

now, when this linkbutton is clicked,your rowcommand will be called, in which you can get the dropdownlist and textbox's value through the method that i specified two posts back.

Can u please tell me how can I retrieve Id in gridview of rowcommand ...
I didn't get of your preivious post of geting id of row using e.commandname.....
Declration of code will helpul to me.
Apr 5 '07 #8
gomzi
304 100+
Can u please tell me how can I retrieve Id in gridview of rowcommand ...
I didn't get of your preivious post of geting id of row using e.commandname.....
Declration of code will helpul to me.
hm..... this should clear your doubts....

(add the necessary attributes)

<gridview>
<columns>
<asp:templatefield>
<itemtemplate>
PLACE THE TEXTBOX AND DROPDOWN HERE OR SEPARATELY USING ANOTHER TEMPLATE FIELD
</itemtemplate>
</asp:templatefield>
<asp:templatefield>
<itemtemplate>
<asp:linkbutton id="submit" runat="server" commandname='<%# DataBinder.Eval(Container.DataItem("YOUR ID COLUMN NAME"))%>'>
</itemtemplate>
</asp:templatefield>
</columns>
</gridview>

now in the code behind,
in gridview_rowcommand,

retrieve the value of id using,

dim selectedid as integer = 0
selectedid = e.commandname

then use the selected id as the need may b.
Apr 5 '07 #9
Tankuuuu very much Gomzi..........it reallly help me lot.
Apr 6 '07 #10
Tankuuuu very much Gomzi..........it reallly help me lot.

I Still have an problem in getting number of selected row in row command.....
I m using ur previos code in my row command event....see below.

in gridview rowcommand,
get the value of the selected dropdown box by,
ctype(me.gridview.rows(the number of the selected row in gridview).findcontrol("yourdropdownbox"),dropdownlist).sel ectedvalue


In above how can i get the number of the selected row of grid view ..?
Apr 6 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Dabbler | last post by:
I have a dropdownlist in a GridView ItemTemplate. I need to bind the ddl to an SqlDataSource, then have a value from a boundfield in the row be passed as the keyfield for select where clause. Im...
0
by: dawg1998 | last post by:
I am able to populate a DropDownList control within multiple rows of a GridView with the following code: `````````````````````````````````````````````````````` <asp:GridView id="gvGridView"...
0
by: Ben | last post by:
Hi, It's about a database containing (for simplifying) three fields: 'placenr' (primary key), 'place' and 'color'. The records are updatable (Edit/Update button) in a gridview. For updating the...
7
by: AG | last post by:
Hi, ASP.NET 2.0 web app I have a GridView utilizing template columns and bound to an objectdatasource. In the edit template of one column there is a dropdownlist bound to another...
0
by: sgtmarcjones | last post by:
How do I access a dropdownlist that is nested within a Formview ItemTemplate Gridview Template? I want to see a label (lgbTimeKeep ! TextValue of ddlName dropdownlist) instead of a dropdownlist...
3
by: Brian VanDyke | last post by:
I have to display a table with customer data (GridView). However, I want to be able to show DropDownList controls inside one of the columns, not just textbox controls. Is this possible? Is it...
0
by: lamolap | last post by:
i have 1 gridview , a dropdownlist inside a gridview and a commandfield of (edit, update and cancel) my gidview looks like this Edit Surname Initials ...
1
by: Anilsg | last post by:
Hi all, I have the DropDownList in the FormView,inside InsertTemplateField The data is binded in run time to it in codebehind page,FOr the First time the page is loaded the DropdownList is...
0
by: Anilsg | last post by:
Hi all, I have the DropDownList in the FormView,inside InsertTemplateField The data is binded in run time to it in codebehind page,FOr the First time the page is loaded the DropdownList...
0
by: Fabrizio | last post by:
Hi all. I have a field in a gridview as templatefield which is a label in view mode and a dropdownlist in edit mode with his datasource. This gridview is inserted as templatefield in another...
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
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...
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...
0
marktang
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,...
0
Oralloy
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,...
0
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...
0
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...
0
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...

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.