Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > strange problem with EditItemTemplate

Reply
Thread Tools

strange problem with EditItemTemplate

 
 
Ben
Guest
Posts: n/a
 
      08-17-2006
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>
<asparameter Name="team" Type="String" />
<asparameter Name="color" Type="String" />

<asparameter Name="original_team" Type="String" />
<asparameter 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>

<aspropDownList ID="drd"
runat="server" AutoPostBack="True">
</aspropDownList>
.....

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


 
Reply With Quote
 
 
 
 
rayfusion@gmail.com
Guest
Posts: n/a
 
      09-04-2006
Hi Ben, I am having the same issue. Did you ever figure this one out?

Ben wrote:

> 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>
> <asparameter Name="team" Type="String" />
> <asparameter Name="color" Type="String" />
>
> <asparameter Name="original_team" Type="String" />
> <asparameter 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>
>
> <aspropDownList ID="drd"
> runat="server" AutoPostBack="True">
> </aspropDownList>
> ....
>
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem using DropDownList in EditItemTemplate Jeff ASP .Net 0 11-13-2008 01:35 PM
No Value: DropDownlist in EditItemTemplate Gridview Problem =?Utf-8?B?ZGVuIDIwMDU=?= ASP .Net 0 10-11-2006 11:34 AM
strange problem with EditItemTemplate Ben ASP .Net Web Controls 1 09-04-2006 02:41 PM
how do i access a dropdownlists selected value in a datagrid edititemtemplate column from the selectedindexchanged event of another dropdownlist in a datagrid edititemtemplate column Dave M ASP .Net Datagrid Control 0 12-14-2004 11:53 AM
problem with button and listbox in edititemtemplate yamne ASP .Net 1 06-17-2004 02:44 PM



Advertisments