www.webdeveloper.com
Results 1 to 8 of 8

Thread: update event dosen't fire when grouping gridView with GridViewHelper

  1. #1
    Join Date
    Apr 2005
    Posts
    9

    update event dosen't fire when grouping gridView with GridViewHelper

    I'm working with a gridView and I already did Edit on Grid which worked just fine.But when I grouped a column using GridViewHelper,it just doesn't work anymore.Any ideea why?
    I've noticed using OnUpdateRow function that when I choose Update it takes Edit as e.CommandName,but when I choose Cancel it takes Cancel,so it's only a problem with the Update.
    Also I have the onUpdatingRow function when used with grouping,it dosen't fire.

  2. #2
    Join Date
    Jan 2003
    Location
    Dundee, Scotland
    Posts
    1,367
    Hi,
    can you post code.
    Did you try RowUpdating, this fires just before the update and also before RowUpdated. You can add some error handling to workout if there is a problem before attempting to update the row.

    Something like this:
    Code:
            If args.StatementType = StatementType.Insert Then
                Dim tw As System.IO.TextWriter = System.IO.File.AppendText("Error.log")
                'tw.WriteLine("{0}: Cookie {1} Updated.", DateTime.Now, args.Row("CookieID", DataRowVersion.Original), args.Row("DateCreated", DataRowVersion.Original))
                tw.Close()
            End If
    ----------------------------------

  3. #3
    Join Date
    Apr 2005
    Posts
    9
    I've tried RowUpdating,but strangely it dosen't even go through taht code.I have a break point in my RowUpdating function but it dosen't even go there at all.
    Here is my code:
    <asp:GridView ID="cmdGridView" runat="server" DataKeyNames ="ComandaPosId"
    BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px"
    CellPadding="4" DataSourceID="cmdObjectData" ForeColor="Black" GridLines="Vertical"
    AutoGenerateColumns="False" EnableViewState="False" OnRowCommand="grdCmd_RowCommand"
    OnRowUpdating="GridView1_RowAdding" >
    <Columns >
    <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />

    <asp:BoundField DataField="ComandaPosId" HeaderText="ComandaPosId" InsertVisible="False"
    ReadOnly="True" SortExpression="ComandaPosId" Visible="False" />

    <asp:TemplateField HeaderText ="GrupaFamDen" SortExpression="grupaFamDen">
    <ItemTemplate>
    <asp:Label ID="grupaFamDen" runat ="server" Text ='<%# Eval("grupaFamDen") %>'/>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:BoundField DataField="ComandaPosId" HeaderText="ComandaPosId" Visible="False" />
    <asp:TemplateField HeaderText ="Produs">
    <ItemTemplate>
    <asp:Label ID="Denumire" runat ="server" Text ='<%# Eval("Denumire") %>'/>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Cantitate" SortExpression="Cantitate">
    <EditItemTemplate>
    <asp:TextBox ID="txtCantitate" runat="server" Text='<%# Bind("Cantitate") %>' Width="50px"></asp:TextBox>
    </EditItemTemplate>
    <ItemTemplate>
    <asp:Label ID="lblCantitate" runat="server" Text='<%# Bind("Cantitate") %>' ></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText ="Pret">
    <ItemTemplate>
    <asp:Label ID="Pret" runat ="server" Text ='<%# Eval("PretEfectiv") %>'/>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText ="Valoare">
    <ItemTemplate>
    <asp:Label ID="Valoare" Text='<%# Eval("Valoare") %>' Runat="Server" />
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Observatie" SortExpression="ObsProdus">
    <EditItemTemplate>
    <asp:TextBox ID="txtObsProdus" runat="server" Text='<%# Bind("ObsProdus") %>' Width="50px"></asp:TextBox>
    </EditItemTemplate>
    <ItemTemplate>
    <asp:Label ID="lblObsProdus" runat="server" Text='<%# Bind("ObsProdus") %>' ></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView>



    <asp:ObjectDataSource ID="cmdObjectData" runat="server" TypeName="DataAcces"
    SelectMethod="GetComanda"
    UpdateMethod="EditComandaPos"
    DeleteMethod="DeleteComandaPos">
    <SelectParameters>
    <asp:SessionParameter DefaultValue="0" Name="userId" SessionField="userId" Type="Int32" />
    <asp:SessionParameter DefaultValue="0" Name="clientId" SessionField="clientId" Type="Int32" />
    <asp:Parameter DefaultValue="0" Name="prelucrata" Type="Int32" />
    </SelectParameters>
    <UpdateParameters >
    <asp:Parameter Name ="Cantitate" Type ="Decimal" />
    <asp:Parameter Name ="ObsProdus" Type ="String" />
    </UpdateParameters>
    </asp:ObjectDataSource>


    protected void GridView1_RowAdding(object sender, GridViewUpdateEventArgs e)
    {


    if (e.RowIndex > 0)
    {
    System.Collections.Hashtable h = new System.Collections.Hashtable();

    foreach (System.Collections.DictionaryEntry x in e.NewValues)
    {
    h[x.Key] = x.Value;
    }
    }
    }

    So in this function I do have a break point ,but I noticed that it never enters this code,so I don't understand why.

  4. #4
    Join Date
    Jan 2003
    Location
    Dundee, Scotland
    Posts
    1,367
    can i see the code for EditComandaPos?
    Not used the gridview control so not sure why this : OnRowUpdating="GridView1_RowAdding" is not firing. I add the OnRowUpdating handler to my data adapter.
    ----------------------------------

  5. #5
    Join Date
    Apr 2005
    Posts
    9
    public static void EditComandaPos(int comandaPosId,decimal cantitate,string obsProdus)
    {

    using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["GeneralConnection"].ConnectionString))
    {
    using (SqlCommand command = new SqlCommand("COMENZIPOS_UPDATE", connection))
    {
    command.CommandType = CommandType.StoredProcedure;
    command.Parameters.Add(new SqlParameter("@comandaPosId", comandaPosId));
    command.Parameters.Add(new SqlParameter("@cantitate", cantitate));
    command.Parameters.Add(new SqlParameter("@obsProdus", obsProdus ));
    connection.Open();
    command.ExecuteNonQuery();

    }
    }
    }

  6. #6
    Join Date
    Jan 2003
    Location
    Dundee, Scotland
    Posts
    1,367
    ok, check your stored procedure and make sure that you are passing the correct number of parameters to it. In the editComandaPos code you have 3 parameters but i looks like your only passing 2 in the update paramaters.
    ----------------------------------

  7. #7
    Join Date
    Apr 2005
    Posts
    9
    Unfortunetly that't not the problem.
    I'm passing only 2 parameters because the third one is the DataKeyNames from gridView (DataKeyNames ="ComandaPosId") which is taken implicitly.
    Anyway I've tried passing all three parameters like this

    <UpdateParameters >
    <asp:Parameter Name="comandaPosId" Type="Int32" />
    <asp:Parameter Name ="Cantitate" Type ="Decimal" />
    <asp:Parameter Name ="ObsProdus" Type ="String" />
    </UpdateParameters

    just to make sure,and that's not the problem.

    This is the code for grouping..maybe that helps

    GridViewHelper helper = new GridViewHelper(this.cmdGridView);
    helper.RegisterGroup("grupaFamDen", true, true);
    helper.GroupHeader += new GroupEvent(helper_GroupHeader);

  8. #8
    Join Date
    Jan 2003
    Location
    Dundee, Scotland
    Posts
    1,367
    ok never used GridViewHelper before so not sure what it can be, however i did have a look for a few examples and came up with this for you to try.
    A couple of examples had this line of code at the end:

    Code:
    helper.ApplyGroupSort();
    ----------------------------------

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles