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

Dropdowlist in a gridview in edit mode

Hi!, I am using framework 2.0 and Visual Visual Web Developer Express.
In a gridview, when it is in editmode, I have a dropdownlist in a
templatefield. The problem is that it show always the first item in the list
and not the current one correspondin to the value saved in the database....
How can I solve the problem? I have read about the event itemdatabound of
the gridview, but if I try the code below:

Sub GridView1_ItemDataBound(ByVal Sender As Object, ByVal e As
DataGridItemEventArgs)
If e.Item.ItemType = ListItemType.EditItem Then
Dim ddl As DropDownList
ddl = CType(e.Item.FindControl("comboTipoIndennita"), DropDownList)
ddl.SelectedIndex =
ddl.Items.IndexOf(ddl.Items.FindByText(DataBinder. Eval(e.Item.DataItem,
"comboTipoIndennita")))
End If
End Sub

it says me that the gridview can't handles that event...
Thanks in advance and sorry for my english...
Marco

Nov 19 '05 #1
6 3478
Sub GridView1_ItemDataBound(ByVal Sender As Object, ByVal e As
DataGridItemEventArgs) <--DataGridItemEventArgs is that suppose to be
GridView.... EventArgs?

Nov 19 '05 #2
"NIan" <we*******@gmail.com> ha scritto nel messaggio
news:11**********************@g14g2000cwa.googlegr oups.com...
Sub GridView1_ItemDataBound(ByVal Sender As Object, ByVal e As
DataGridItemEventArgs) <--DataGridItemEventArgs is that suppose to be
GridView.... EventArgs?

what you mean? I am not very skilled.. can you paste an example of code that
work?
TNX
Nov 19 '05 #3
Try going through this at:-
http://winfx.msdn.microsoft.com/libr...ry/en-us/cpref
/html/E_System_Web_UI_WebControls_GridView_RowDataBound. asp
It should guide you.
Patrick
"Lupakkiotto" <ta***@despammed.com> wrote in message
news:3t************@individual.net...
"NIan" <we*******@gmail.com> ha scritto nel messaggio
news:11**********************@g14g2000cwa.googlegr oups.com...
Sub GridView1_ItemDataBound(ByVal Sender As Object, ByVal e As
DataGridItemEventArgs) <--DataGridItemEventArgs is that suppose to be
GridView.... EventArgs?

what you mean? I am not very skilled.. can you paste an example of code

that work?
TNX

Nov 19 '05 #4
"Patrick.O.Ige" <pa********@optusnet.com.au> ha scritto nel messaggio
news:OH**************@TK2MSFTNGP14.phx.gbl...
Try going through this at:-
http://winfx.msdn.microsoft.com/libr...ry/en-us/cpref
/html/E_System_Web_UI_WebControls_GridView_RowDataBound. asp
It should guide you.
Patrick


thank.. I tried to modify the code in:
Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As
GridViewRowEventArgs)

If e.Row.RowType = ListItemType.EditItem Then

Dim ddl As DropDownList

ddl = CType(e.Row.FindControl("comboTipoIndennita"), DropDownList)

'ddl.SelectedIndex =
ddl.Items.IndexOf(ddl.Items.FindByText(DataBinder. Eval(e.Row.DataItem,
"comboTipoIndennita")))

ddl.SelectedValue =
ddl.Items.IndexOf(ddl.Items.FindByText(DataBinder. Eval(e.Row.DataItem,
"TipoIndennita")))

End If

End Sub

but nothing happen...
Nov 19 '05 #5
I solved my problem in a very simple way:
<asp:DropDownList runat="server" ID="comboTipoIndennita"
DataSourceID="SqlDataSource2" DataTextField="TipoIndennita"
DataValueField="idIndennitaGruppo" CssClass="combo" SelectedValue='<%#
Bind("myID")%>' />

setting SelectedValue='<%# Bind("myID")%>
Tnx
Nov 19 '05 #6
Good Lupakkiotto you got it working.
Patrick
"Lupakkiotto" <ta***@despammed.com> wrote in message
news:3t************@individual.net...
I solved my problem in a very simple way:
<asp:DropDownList runat="server" ID="comboTipoIndennita"
DataSourceID="SqlDataSource2" DataTextField="TipoIndennita"
DataValueField="idIndennitaGruppo" CssClass="combo" SelectedValue='<%#
Bind("myID")%>' />

setting SelectedValue='<%# Bind("myID")%>
Tnx

Nov 19 '05 #7

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

Similar topics

1
by: John A Grandy | last post by:
I'm not using SqlDataSource or ObjectDataSource. I'm handling events , similar to approach commonly used in 1.1. DataGrid. My question is : How do I configure a GridView's edit mode row format ?...
3
by: misiek | last post by:
Hi all. I have following problem: 1. In my web page I have a GridView control, which does not have a DataSourceId set in designer. 2. When user presses Start button then I create...
4
by: | last post by:
I wanted better control over the display of the command buttons, so I created Template columns for each command. (Otherwise the GridView was putting extras spacing around the images and such.) ...
3
by: cpnet | last post by:
I have a GridView which I'm populating from an ObjectDataSource (give the GridView a DataTable). The GridView will have about 20 rows, and only one editable column. The editable column consists...
0
by: tim.cavins | last post by:
I am trying a GridView for the first time and it seems to be something that should be EXTREMELY simple. I cannot get the Update or Cancel when trying to edit a row to work. When I click on the...
1
by: Evan M. | last post by:
Here's my GridView and my SqlDataSource <asp:GridView ID="ContactHistoryGrid" runat="server" AutoGenerateColumns="False" DataSourceID="ContactHistoryDS" DataKeyNames="JobHistoryID"...
0
by: Larry Bud | last post by:
After spending two days looking at the options in adding a row to a gridview, I came up with my own that I'd like to share. I only can share pseudo-code right now, but maybe in the future I'll...
3
by: pvong | last post by:
VB.NET How do you change a gridview from Update mode to normal mode? I'm usually dealing for Formviews and there is a ChangeMode option but I don't see one for Gridviews.
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.