HighTechTalks DotNet Forums  

which expert can finally solve this?

ASP.net Data Grid Control microsoft.public.dotnet.framework.aspnet.datagridcontrol


Discuss which expert can finally solve this? in the ASP.net Data Grid Control forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Cas
 
Posts: n/a

Default which expert can finally solve this? - 08-21-2006 , 07:50 AM






Hi,

I tried to solve this for a while, but there is always somewhere a problem.
Here my story:
The table contains two fields (field1, field2).
I use a gridview for editing the table: field1 can be updated manually, but
field2 must be updated with the selectedvalue of a dropdownlist. So I
checked the SelectedIndex and if it's >0 (first element is only a message),
i created a controlparameter which is necessary for the link with the
selectedvalue.

This is the code here below: it works only for field1 AND if the
DropDownList1.SelectedIndex is not >0 (means first item or no click). No
error, but I can't update field2.

I think that the problem is:
SqlDataSource1.UpdateCommand="UPDATE [mytable] SET [field1] = ?,[field2] =
?" (in code-behind), but I have no idea how to correct this.

If you know it, please tell me
Thanks
Cas


aspx code:
---------
<asp:SqlDataSource ID="SqlDataSource1 ...
SelectCommand="SELECT * FROM [mytable]"
UpdateCommand="UPDATE [mytable] SET [field1] = ?"
<UpdateParameters>
<asp:Parameter Name="field1" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>

<asp:GridView ID="GridView1" ...
<Columns>
<asp:CommandField ShowEditButton="True"/>
<asp:BoundField DataField="field1" />
<asp:BoundField DataField="field2" />
</Columns>
</asp:GridView>

<aspropDownList ID="DropDownList1" ...
</aspropDownList>

code-behind:
-----------
Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As

System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles
GridView1.RowUpdating
If DropDownList1.SelectedIndex > 0 Then
Dim a As New ControlParameter
a.ControlID = "Dropdownlist1"
a.Type = TypeCode.String
a.PropertyName = "SelectedValue"
SqlDataSource1.UpdateParameters.Add(a)
SqlDataSource1.UpdateCommand="UPDATE [mytable] SET [field1] = ?,[field2]
= ?"
End If
End Sub



Reply With Quote
  #2  
Old   
Cas
 
Posts: n/a

Default Re: which expert can finally solve this? - 08-21-2006 , 08:25 AM






I found it ....
the line sqldatasource1.update()
was missing



"Cas" <s@s> schreef in bericht news:esKv2fRxGHA.1224 (AT) TK2MSFTNGP03 (DOT) phx.gbl...
Quote:
Hi,

I tried to solve this for a while, but there is always somewhere a
problem.
Here my story:
The table contains two fields (field1, field2).
I use a gridview for editing the table: field1 can be updated manually,
but field2 must be updated with the selectedvalue of a dropdownlist. So I
checked the SelectedIndex and if it's >0 (first element is only a
message), i created a controlparameter which is necessary for the link
with the selectedvalue.

This is the code here below: it works only for field1 AND if the
DropDownList1.SelectedIndex is not >0 (means first item or no click). No
error, but I can't update field2.

I think that the problem is:
SqlDataSource1.UpdateCommand="UPDATE [mytable] SET [field1] = ?,[field2] =
?" (in code-behind), but I have no idea how to correct this.

If you know it, please tell me
Thanks
Cas


aspx code:
---------
asp:SqlDataSource ID="SqlDataSource1 ...
SelectCommand="SELECT * FROM [mytable]"
UpdateCommand="UPDATE [mytable] SET [field1] = ?"
UpdateParameters
asp:Parameter Name="field1" Type="String" /
/UpdateParameters
/asp:SqlDataSource

asp:GridView ID="GridView1" ...
Columns
asp:CommandField ShowEditButton="True"/
asp:BoundField DataField="field1" /
asp:BoundField DataField="field2" /
/Columns
/asp:GridView

aspropDownList ID="DropDownList1" ...
/aspropDownList

code-behind:
-----------
Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As

System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles
GridView1.RowUpdating
If DropDownList1.SelectedIndex > 0 Then
Dim a As New ControlParameter
a.ControlID = "Dropdownlist1"
a.Type = TypeCode.String
a.PropertyName = "SelectedValue"
SqlDataSource1.UpdateParameters.Add(a)
SqlDataSource1.UpdateCommand="UPDATE [mytable] SET [field1] = ?,[field2]
= ?"
End If
End Sub




Reply With Quote
  #3  
Old   
Bruno Alexandre
 
Posts: n/a

Default Re: which expert can finally solve this? - 08-21-2006 , 09:00 AM



see, you are a wonderful expert! ;-)

--

Bruno Alexandre
"a Portuguese in København, Danmark"



"Cas" <s@s> escreveu na mensagem
news:uR7hmzRxGHA.324 (AT) TK2MSFTNGP06 (DOT) phx.gbl...
Quote:
I found it ....
the line sqldatasource1.update()
was missing



"Cas" <s@s> schreef in bericht
news:esKv2fRxGHA.1224 (AT) TK2MSFTNGP03 (DOT) phx.gbl...
Hi,

I tried to solve this for a while, but there is always somewhere a
problem.
Here my story:
The table contains two fields (field1, field2).
I use a gridview for editing the table: field1 can be updated manually,
but field2 must be updated with the selectedvalue of a dropdownlist. So I
checked the SelectedIndex and if it's >0 (first element is only a
message), i created a controlparameter which is necessary for the link
with the selectedvalue.

This is the code here below: it works only for field1 AND if the
DropDownList1.SelectedIndex is not >0 (means first item or no click). No
error, but I can't update field2.

I think that the problem is:
SqlDataSource1.UpdateCommand="UPDATE [mytable] SET [field1] = ?,[field2]
= ?" (in code-behind), but I have no idea how to correct this.

If you know it, please tell me
Thanks
Cas


aspx code:
---------
asp:SqlDataSource ID="SqlDataSource1 ...
SelectCommand="SELECT * FROM [mytable]"
UpdateCommand="UPDATE [mytable] SET [field1] = ?"
UpdateParameters
asp:Parameter Name="field1" Type="String" /
/UpdateParameters
/asp:SqlDataSource

asp:GridView ID="GridView1" ...
Columns
asp:CommandField ShowEditButton="True"/
asp:BoundField DataField="field1" /
asp:BoundField DataField="field2" /
/Columns
/asp:GridView

aspropDownList ID="DropDownList1" ...
/aspropDownList

code-behind:
-----------
Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As

System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles
GridView1.RowUpdating
If DropDownList1.SelectedIndex > 0 Then
Dim a As New ControlParameter
a.ControlID = "Dropdownlist1"
a.Type = TypeCode.String
a.PropertyName = "SelectedValue"
SqlDataSource1.UpdateParameters.Add(a)
SqlDataSource1.UpdateCommand="UPDATE [mytable] SET [field1] =
?,[field2] = ?"
End If
End Sub






Reply With Quote
  #4  
Old   
msnews
 
Posts: n/a

Default Re: which expert can finally solve this? - 09-11-2006 , 07:25 AM



Do you have field2 defined as an UpdateParameter? It appears you only have
field1 listed.

Change...

<UpdateParameters>
<asp:Parameter Name="field1" Type="String" />
</UpdateParameters>

To...

<UpdateParameters>
<asp:Parameter Name="field1" Type="String" />
<asp:Parameter Name="field2" Type="String" />
</UpdateParameters>

See if that works.

Brennan Stehling
http://brennan.offwhite.net/blog/


"Cas" <s@s> wrote

Quote:
Hi,

I tried to solve this for a while, but there is always somewhere a
problem.
Here my story:
The table contains two fields (field1, field2).
I use a gridview for editing the table: field1 can be updated manually,
but field2 must be updated with the selectedvalue of a dropdownlist. So I
checked the SelectedIndex and if it's >0 (first element is only a
message), i created a controlparameter which is necessary for the link
with the selectedvalue.

This is the code here below: it works only for field1 AND if the
DropDownList1.SelectedIndex is not >0 (means first item or no click). No
error, but I can't update field2.

I think that the problem is:
SqlDataSource1.UpdateCommand="UPDATE [mytable] SET [field1] = ?,[field2] =
?" (in code-behind), but I have no idea how to correct this.

If you know it, please tell me
Thanks
Cas


aspx code:
---------
asp:SqlDataSource ID="SqlDataSource1 ...
SelectCommand="SELECT * FROM [mytable]"
UpdateCommand="UPDATE [mytable] SET [field1] = ?"
UpdateParameters
asp:Parameter Name="field1" Type="String" /
/UpdateParameters
/asp:SqlDataSource

asp:GridView ID="GridView1" ...
Columns
asp:CommandField ShowEditButton="True"/
asp:BoundField DataField="field1" /
asp:BoundField DataField="field2" /
/Columns
/asp:GridView

aspropDownList ID="DropDownList1" ...
/aspropDownList

code-behind:
-----------
Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As

System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles
GridView1.RowUpdating
If DropDownList1.SelectedIndex > 0 Then
Dim a As New ControlParameter
a.ControlID = "Dropdownlist1"
a.Type = TypeCode.String
a.PropertyName = "SelectedValue"
SqlDataSource1.UpdateParameters.Add(a)
SqlDataSource1.UpdateCommand="UPDATE [mytable] SET [field1] = ?,[field2]
= ?"
End If
End Sub




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.