strange problem with EditItemTemplate

B

Ben

Hi,

It's about a table with two fields: 'team' and 'color'. Each team has a
color.
What I want is to update the field 'color' in the gridview only with the
selected value of the dropdownlist, which is bound to a table ('colortable')
with one field ('allcolor') containing all available colors.

My problem is this:
When clicking on 'Edit' button in the gridview, the value shown into the
<EditItemTemplate> in the gridview is always the first element of the
dropdownlist ('pickup'). When clicking on 'Update' button, the field 'color'
becomes empty.

In the <body>, i put <%=dd%> for testing the selected value of the
dropdownlist, and the value is right on each click in the dropdownlist. So
why does Text='<%#dd%>'in the <EditItemTemplate> only show the first value
and why does the update not work ?

Thanks for any help
Ben

code in aspx:
-------------
<body>
this is used as test and shows the selected value of the dropdownlist:<%=dd
%>
.....
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="..."
SelectCommand="SELECT * FROM [mytable]"
OldValuesParameterFormatString="original_{0}"
ProviderName="System.Data.OleDb"
UpdateCommand = "UPDATE [mytable] SET [color] = ? where [team] = ?" >
<UpdateParameters>
<asp:parameter Name="team" Type="String" />
<asp:parameter Name="color" Type="String" />

<asp:parameter Name="original_team" Type="String" />
<asp:parameter Name="original_color" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>

<asp:GridView ID="GridView1" runat="server" DataKeyNames="field1"
DataSourceID="SqlDataSource1" >
<Columns>
<asp:CommandField ShowEditButton="True"/>
<asp:BoundField DataField="team" />
<asp:TemplateField HeaderText="color">
<ItemTemplate>
<asp:Label ID="kl" Runat="server" Text='<%# Bind("color")
%>'></asp:Label>
</ItemTemplate>

<EditItemTemplate>
<asp:TextBox ID="kl" ReadOnly="True" Runat="server" Text='<%#dd%>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

<asp:DropDownList ID="drd"
runat="server" AutoPostBack="True">
</asp:DropDownList>
.....

code-behind:
-----------
friend dd as string
....
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
Dim ...
Dim ...
sConnectionString = "Provider = ...
sql = "SELECT [allcolor] FROM [colortable];"
d = New OleDbDataAdapter(sql, sConnectionString)
ds = New DataSet()
x = d.Fill(ds)
If Page.IsPostBack Then
dd = drd.SelectedValue
drd.Items.Clear()
End If
z = New ListItem("pick up a color", "pickup")
drd.Items.Add(z)
For i = 0 To x - 1
kl = ds.Tables(0).Rows(i).Item(0)
z = New ListItem(kl, kl)
drd.Items.Add(z)
Next
End Sub
End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top