Bound to GridView - edit button not working

Posts   
 
    
daz_oldham avatar
daz_oldham
User
Posts: 62
Joined: 20-Jul-2007
# Posted on: 04-Oct-2007 14:49:28   

Hello

I don't know if this is because I'm using LLBL or if it is a genreral .NET problem.

However, I'm binding my data to a GridView, but when I click the edit button, it as if nothing happens - I certainly don't get my EditTemplate for the fields.


ProductTypeOptionAttributeCombinationCollection combos = new ProductTypeOptionAttributeCombinationCollection();

        PredicateExpression filter = new PredicateExpression();
        filter.Add(ProductTypeOptionAttributeCombinationFields.ProductId == m_iProductID);

        LLBLGenProDataSource dsCombos = new LLBLGenProDataSource();
        dsCombos.CacheLocation = DataSourceCacheLocation.Session;
        dsCombos.DataContainerType = DataSourceDataContainerType.EntityCollection;
        dsCombos.EnablePaging = false;
        dsCombos.EntityCollection = combos;
        dsCombos.EntityCollectionTypeName = "RedStarEnergy.DAL.CollectionClasses.ProductTypeOptionAttributeCombinationCollection";
        dsCombos.FilterToUse = filter;
        
        gvOptions.DataSource = dsCombos;
        gvOptions.DataBind();

Any help would be really appreciated.

Regards

Darren

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 04-Oct-2007 14:59:33   

Please post the aspx code of the grid.

hint: By default LivePersistence is set to true for the LLBLGenProDataSource, so it will create the collection and fetch it for you. So the following line is not needed: dsCombos.EntityCollection = combos;

daz_oldham avatar
daz_oldham
User
Posts: 62
Joined: 20-Jul-2007
# Posted on: 04-Oct-2007 15:12:36   

Ah - thanks for the tip abou the LivePersistence Walaa simple_smile

Here's my aspx code - it's all pretty much generated by VS - but I've converted one column to a template field to see if it made any difference.

I don't think it makes a difference, but I'm also using the Telerik Tabstrip Control.



<asp:GridView ID="gvOptions" runat="server" AutoGenerateColumns="False"
            CellPadding="4" ForeColor="#333333" GridLines="None" OnRowEditing="gvOptions_RowEditing"
            OnRowUpdated="gvOptions_RowUpdated" OnRowUpdating="gvOptions_RowUpdating">
            <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
            <Columns>
                <asp:TemplateField HeaderText="Name">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="Price" HeaderText="Cost" />
                <asp:BoundField DataField="Quantity" HeaderText="Quantity" />
                <asp:CheckBoxField DataField="InStock" HeaderText="Stock?" />
                <asp:CommandField ButtonType="Button" ShowEditButton="True" />
            </Columns>
            
            <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
            <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
            <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
            <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="White" />
        </asp:GridView>

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 04-Oct-2007 15:41:34   

Maybe that's because you GridView declaration misses the DataKeyNames attribute.

Why don't you use design time databinding, to drop the LLBLGenProDataSource on the form and bind it to the GridView?

Please consult the "ASP.NET 2.0 databinding example" posted in the examples of the v.2.5 download page.

daz_oldham avatar
daz_oldham
User
Posts: 62
Joined: 20-Jul-2007
# Posted on: 04-Oct-2007 15:55:26   

I've tried setting the DataKeyNames to the Primary key, but this didn't make a difference.

How do I drag a LLBLGenProDataSource onto the form - it doesn't appear in my toolbox.

Thanks

Darren

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 04-Oct-2007 16:00:01   

How do I drag a LLBLGenProDataSource onto the form - it doesn't appear in my toolbox.

Quoted from the docs:

This can be done manually by right-clicking the toolbox when a webform is open in the editor (HTML or design view) and then by selecting 'Choose items...' which allows you to browse to the ORMSupportClasses dll for .NET 2.0. It's key you add the ORMSupportClasses dll version you're also using in your ASP.NET project, as VS.NET can load only one version of a given assembly and this could lead to type clashes in the webform designer. This is a problem with VS.NET 2005 and which is almost entirely solved by installing VS.NET 2005 SP1.

daz_oldham avatar
daz_oldham
User
Posts: 62
Joined: 20-Jul-2007
# Posted on: 04-Oct-2007 17:34:09   

Hoorah smile

Thanks very much for all your help Walaa