Click to See Complete Forum and Search --> : update event dosen't fire when grouping gridView with GridViewHelper


biap
05-09-2007, 02:33 AM
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.

Ribeyed
05-09-2007, 12:10 PM
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:

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

biap
05-10-2007, 04:00 AM
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.

Ribeyed
05-10-2007, 05:03 AM
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.

biap
05-10-2007, 05:44 AM
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();

}
}
}

Ribeyed
05-10-2007, 08:08 AM
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.

biap
05-10-2007, 09:10 AM
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);

Ribeyed
05-10-2007, 03:14 PM
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:


helper.ApplyGroupSort();