which expert can finally solve this?

Discussion in 'ASP .Net Datagrid Control' started by Cas, Aug 21, 2006.

  1. Cas

    Cas Guest

    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>

    <asp:DropDownList ID="DropDownList1" ...
    </asp:DropDownList>

    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
    Cas, Aug 21, 2006
    #1
    1. Advertising

  2. Cas

    Cas Guest

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



    "Cas" <s@s> schreef in bericht news:...
    > 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>
    >
    > <asp:DropDownList ID="DropDownList1" ...
    > </asp:DropDownList>
    >
    > 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
    >
    Cas, Aug 21, 2006
    #2
    1. Advertising

  3. see, you are a wonderful expert! ;-)

    --

    Bruno Alexandre
    "a Portuguese in KĂžbenhavn, Danmark"



    "Cas" <s@s> escreveu na mensagem
    news:...
    >I found it ....
    > the line sqldatasource1.update()
    > was missing
    >
    >
    >
    > "Cas" <s@s> schreef in bericht
    > news:...
    >> 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>
    >>
    >> <asp:DropDownList ID="DropDownList1" ...
    >> </asp:DropDownList>
    >>
    >> 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
    >>

    >
    >
    Bruno Alexandre, Aug 21, 2006
    #3
  4. Cas

    msnews Guest

    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 in message news:...
    > 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>
    >
    > <asp:DropDownList ID="DropDownList1" ...
    > </asp:DropDownList>
    >
    > 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
    >
    msnews, Sep 11, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kylin
    Replies:
    0
    Views:
    348
    Kylin
    Jun 20, 2005
  2. David Lozzi

    Try...Catch...Finally not firing finally?

    David Lozzi, Apr 23, 2007, in forum: ASP .Net
    Replies:
    12
    Views:
    783
    Alvin Bruney [MVP]
    May 11, 2007
  3. pplnet
    Replies:
    2
    Views:
    2,604
    marina_yassa
    Mar 29, 2013
  4. nu
    Replies:
    0
    Views:
    218
  5. Cas

    which expert can finally solve this?

    Cas, Aug 21, 2006, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    155
    msnews
    Sep 11, 2006
Loading...

Share This Page