Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 17th, 2006, 08:44 AM
Friend of Wrox
 
Join Date: Apr 2006
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
Default strange problem with EditItemTemplate

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 d As OleDbDataAdapter
            Dim ds As DataSet
            Dim sConnectionString As String
            Dim sql, kl As String
            Dim z As ListItem
            Dim x, i As Integer
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






Similar Threads
Thread Thread Starter Forum Replies Last Post
strange IE problem sully7 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 3 September 19th, 2008 08:44 AM
Strange problem... F3553 C++ Programming 1 October 25th, 2007 03:56 PM
problem with dropdownlist in editItemTemplate hertendreef ASP.NET 2.0 Professional 4 July 31st, 2007 05:56 PM
Strange calculation problem blkskullwork Javascript 4 November 3rd, 2006 03:16 PM
very strange problem! please help! raybristol ASP.NET 1.0 and 1.1 Basics 8 December 15th, 2005 06:46 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.