Solved

gridview edit button

Posted on 2012-03-10
12
685 Views
Last Modified: 2012-03-27
Hi,

I have a gridview that where autogenetrate edit button is set to false.
But I have a link button like so

<asp:Linkbutton id="lnkEdit" runat="server" cssclass="edit" comamndName="edit">Edit</asp:Linkbutton>

So this of course goes into edit mode.

This works fine in IE but not firefox, I have checked that Enable Javascript is enabled as well please help

Thanks,

R8VI
0
Comment
Question by:R8VI
  • 7
  • 5
12 Comments
 
LVL 7

Expert Comment

by:markmiddlemist
ID: 37705621
Are you seeing anything come up in the error console, either on loading the page, or on clicking the link?
0
 

Author Comment

by:R8VI
ID: 37705658
Hi,

Nope I am getting nothing in the Error console at all

ill put my code here to help

aspx page

<asp:GridView ID="grdAgentSpecficProperty" runat="server" AutoGenerateColumns="False"
                OnRowDataBound="RowDataBound" AllowPaging="True" PageSize="5" OnPageIndexChanging="OnPageIndexChanged"
                CssClass="GridMyPropertySale" OnRowEditing="RowEditing" AutoGenerateEditButton="false"
                OnRowCancelingEdit="RowCancelEdit" PagerSettings-Position="TopAndBottom" PagerStyle-HorizontalAlign="Right"
                PagerSettings-NextPageText=">" PagerSettings-PreviousPageText="<" PagerStyle-CssClass="PageingStyle"
                GridLines="None" OnRowUpdating="RowUpdating">
                <Columns>
                    <asp:TemplateField>
 <ItemTemplate>
                            <table cellpadding="5px" class="AgentPropertiesSaleorLet">
                                <tr>
                                    <td rowspan="8" valign="top">
                                        <asp:Image ID="ImageName" runat="server" alt="Property Images" Height="100px" Width="100px"
                                            CssClass="MainImageSale" src='<%#"/Account/MyFiles/"+ Eval("ImageName") %>' />
                                        <asp:Label ID="lblPropertyID" Visible="false" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"PropertyID") %>'></asp:Label>
                                        <br />
                                        <br />
                                        <asp:LinkButton ID="lnkEdit" runat="server" CssClass="EditButton" CommandName="Edit">Edit</asp:LinkButton>
                                    </td>
                                    <td>
                                        <asp:MaskedEditExtender ID="MaskedEditExtender1" TargetControlID="txtPrice" Mask="9, 999, 999"
                                            MaskType="Number" DisplayMoney="Left" runat="server">
                                        </asp:MaskedEditExtender>
                                        <div class="PoundSymbolforPrice">
                                            £
                                            <asp:TextBox ID="txtPrice" runat="server" Width="100px" Text='<%#Eval("Price") %>'
                                                CssClass="PriceStyle"></asp:TextBox>
                                            <asp:Label ID="lblTypeOfPrice" runat="server" CssClass="TypeofPrice" Text='<%#DataBinder.Eval(Container.DataItem,"TypeOfPrice") %>'></asp:Label>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <asp:Label ID="lblPropertyNumber" CssClass="labelsforMyPropertiesAddress" runat="server"
                                            Text='<%#DataBinder.Eval(Container.DataItem,"PropertyNumber") %>'></asp:Label>
                                        <asp:Label ID="lblStreet" CssClass="labelsforMyPropertiesAddress" runat="server"
                                            Text='<%#DataBinder.Eval(Container.DataItem,"Street") %>'></asp:Label>
                                        <asp:Label ID="lblCity" CssClass="labelsforMyPropertiesAddress" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"City") %>'></asp:Label>
                                        <asp:Label ID="lblCounty" CssClass="labelsforMyPropertiesAddress" runat="server"
                                            Text='<%#DataBinder.Eval(Container.DataItem,"County") %>'></asp:Label>
                                        <asp:Label ID="lblPostCode" CssClass="labelsforMyPropertiesAddress" runat="server"
                                            Text='<%#DataBinder.Eval(Container.DataItem,"PostCode") %>'></asp:Label>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <asp:Label ID="lblInfoSaleOrLet" runat="server" CssClass="PropertyInfoLabelsMyProperty"
                                            Text="Property for:"></asp:Label>
                                        <asp:Label ID="lblSaleOrLet" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"SaleOrLet") %>'></asp:Label>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <asp:Label ID="lblInfoPropertyType" runat="server" CssClass="PropertyInfoLabelsMyProperty"
                                            Text="Property Type:"></asp:Label>
                                        <asp:Label ID="lblPropertyType" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"PropertyType") %>'></asp:Label>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <asp:Label ID="lblBedrooms" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"Bedrooms") %>'></asp:Label>
                                        <asp:Label ID="lblBedroomsInfo" runat="server" CssClass="PropertyInfoLabelsMyProperty"
                                            Text="bed"></asp:Label>
                                        |
                                        <asp:Label ID="lblReceptions" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"Receptions") %>'></asp:Label>
                                        <asp:Label ID="lblNewReceptions" runat="server" CssClass="PropertyInfoLabelsMyProperty"
                                            Text="Receptions"></asp:Label>
                                        |
                                        <asp:Label ID="lblBathrooms" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"Bathrooms") %>'></asp:Label>
                                        <asp:Label ID="lblBathroomsNew" runat="server" CssClass="PropertyInfoLabelsMyProperty"
                                            Text="Bathrooms"></asp:Label>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <asp:Label ID="lblServiceChargeorGR" runat="server" CssClass="PropertyInfoLabelsMyProperty"
                                            Text='<%#DataBinder.Eval(Container.DataItem,"ServiceChargeorGR") %>'></asp:Label>
                                        <asp:Label ID="lbServiceCargeamount" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"ServiceChargeorGRAmount") %>'></asp:Label>
                                        |
                                        <asp:Label ID="lblTenure" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"Tenure") %>'></asp:Label>
                                        |
                                        <asp:Label ID="lblCommissionInfo" runat="server" CssClass="PropertyInfoLabelsMyProperty"
                                            Text="Commission:"></asp:Label>
                                        <asp:Label ID="lblCommission" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"Commission") %>'></asp:Label>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <asp:Label ID="lblLease" CssClass="PropertyInfoLabelsMyProperty" runat="server" Text="Years Lease:"></asp:Label>
                                        <asp:Label ID="lblLease2" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"NumberOfYearsLease") %>'></asp:Label>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <asp:TextBox ID="txtDescription" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"Description") %>'
                                            Width="90%" CssClass="txtDescriptionSaleOrLet" Height="80px" TextMode="MultiLine"
                                            MaxLength="250" Style="overflow-y: hidden;"></asp:TextBox>
                                    </td>
                                </tr>
                            </table>
                        </ItemTemplate>
          </asp:TemplateField>
                </Columns>
                <PagerSettings NextPageText="&gt;" Position="TopAndBottom" PreviousPageText="&lt;">
                </PagerSettings>
                <PagerStyle HorizontalAlign="Right" CssClass="PageingStyle"></PagerStyle>
            </asp:GridView>

Open in new window


c sharp i have only put rowedit code as this is the one that is not working

    protected void RowEditing(object sender, GridViewEditEventArgs e)
        {
            grdAgentSpecficProperty.EditIndex = e.NewEditIndex;
            GetPropertiesInfo();

            Label lblSelectedPropertyID = (Label)grdAgentSpecficProperty.Rows[grdAgentSpecficProperty.EditIndex].FindControl("lblPropertyNewID");
            sPropertyID = lblSelectedPropertyID.Text;
            GetImages();
            GetAllImagesWithoutMainImage();
        }

Open in new window


thanks for our help so far

Thanks,

r8vi
0
 
LVL 7

Expert Comment

by:markmiddlemist
ID: 37705708
I'm doing a bit of research as this one has got me intruiged.

To narrow it down in the interim, if you add a RowCommand handler and change the commandname to somthing nonstandard does that fail in firefox well?
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:R8VI
ID: 37705730
Hi,

I tried that and changed it to command name as test and it worked fine,

That could be the soultion but how do i then put the grid view in edit mode

Thanks,

R8VI
0
 
LVL 7

Expert Comment

by:markmiddlemist
ID: 37705766
As I understand it you would need to set the EditIndex value on the GridView  to the index of the row in question (or -1 for no row).

The problem you have then is that the row index is not directly accessible in the RowCommand, so I would suggest that in the rowdatabound handler you assign the index to the CommandArgument of the LinkButton, then use this to set the editindex in the command handler.

I know its a bit hacky but it should (theoretically) work
0
 

Author Comment

by:R8VI
ID: 37705790
Hi,

Do you have a code sample please ? Or a link that I can see what you mean ?

Thanks,

R8vi
0
 
LVL 7

Accepted Solution

by:
markmiddlemist earned 500 total points
ID: 37705900
ok, using the pattern I normally follow you'll need the following function:

public Control FindControlRecursive(Control container, string name)
{
    if (container.ID == name)
        return container;

    foreach (Control ctrl in container.Controls)
    {
        Control foundCtrl = FindControlRecursive(ctrl, name);
        if (foundCtrl != null)
            return foundCtrl;
    }
    return null;
}

Add a RowDataBound handler to your GridView with the following:

        if (e.Row.RowType == DataControlRowType.DataRow)
        {
                LinkButton lnkEdit =
                    (LinkButton)FindControlRecursive(e.Row, "lnkEdit");
               
               lnkEdit.CommandArgument = e.Row.RowIndex.ToString();
        }

Then in your RowCommand handler, where the commandname matches your edit command string:

YourGridView.EditIndex = Convert.ToInt32(e.CommandArgument);

hope this helps
0
 

Author Comment

by:R8VI
ID: 37706395
Hi, I am sorry I am really struggling with this is there somewhere I can follow a full tutorial
for example did you man RowDataBound  or RowCommand as if cant find e.command name in Rowdatabound
0
 

Author Comment

by:R8VI
ID: 37706398
this is what i have so far

    protected void RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "EditCommand")
            {
                GridViewRow CurrentRow = grdAgentSpecficProperty.SelectedRow;
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    LinkButton lnkEdit = (LinkButton)FindControl("lnkEdit");
                    int rowIndex = Convert.ToInt32(lnkEdit.CommandArgument);
                    grdAgentSpecficProperty.EditIndex = rowIndex;
                }

                
            }



 <asp:LinkButton ID="lnkEdit" runat="server" CssClass="EditButton" CommandName="EditCommand" CommandArgument='<%# Container.DataItemIndex %>'>Edit</asp:LinkButton>
        }

Open in new window

0
 

Author Comment

by:R8VI
ID: 37706452
Hi,

having thought about this there are other places on the site that I have a link button and they dont work either so maybe trying to get to the bottom of why they dont work is a better solution.
I am not sure if you have had time to investigate on it at the moment ?

Thanks,r8VI
0
 
LVL 7

Expert Comment

by:markmiddlemist
ID: 37706651
for the RowDatabound you should just need to create the event handler and post the code in I posted above:

        if (e.Row.RowType == DataControlRowType.DataRow)
        {
                LinkButton lnkEdit =
                    (LinkButton)FindControlRecursive(e.Row, "lnkEdit");
               
               lnkEdit.CommandArgument = e.Row.RowIndex.ToString();
        }

I've been trying to find out what problems other people have had in FireFox and have yet to find anything useful - I find it very hard to believe that you're the first person to ever have this problem.

It might be an idea to also post your issue up on the forums at asp.net - a lot of people with more specialised knowledge than me, including microsoft employees and MVPs monitor those boards

Sorry I can't be more help
0
 

Author Comment

by:R8VI
ID: 37706687
Hi,

Thanks for this quick question this is what I am doing

        public Control FindControlRecursive(Control container, string name)
        {
            if (container.ID == name)
                return container;

            foreach (Control ctrl in container.Controls)
            {
                Control foundCtrl = FindControlRecursive(ctrl, name);
                if (foundCtrl != null)
                    return foundCtrl;
            }
            return null;
        }


protected void RowDataBound(object sender, GridViewRowEventArgs e)
        {
            int iCountPages = grdAgentSpecficProperty.PageCount;
            int iCurrentPage = grdAgentSpecficProperty.PageIndex + 1;


            lblTotalPageCount.Text = "Page " + Convert.ToString(iCurrentPage) + " of " + Convert.ToString(iCountPages);

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
               /* LinkButton lnkEdit =
                    (LinkButton)FindControlRecursive(e.Row, "lnkEditButton");*/
                int iCountNumberofRows = grdAgentSpecficProperty.Rows.Count;
                int i;

                if (iCountNumberofRows == 0)
                {
                    LinkButton lnkEditButton = (LinkButton)grdAgentSpecficProperty.Rows[0].FindControl("lnkEditButton");
                    lnkEditButton.CommandArgument = e.Row.RowIndex.ToString();
                }
                else
                {
                    for (i = 0; i < iCountNumberofRows; i++)
                    {

                        LinkButton lnkEditButton = (LinkButton)grdAgentSpecficProperty.Rows[i].FindControl("lnkEditButton");
                        lnkEditButton.CommandArgument = e.Row.RowIndex.ToString();
                    }
                }
            }

        }

      protected void RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "EditMode")
            {
                grdAgentSpecficProperty.EditIndex = Convert.ToInt32(e.CommandArgument);
                GetPropertiesInfo();
                
            }
}

Open in new window


But my problem now is that how do i trap if use has clicked on the first row ?
I tried
                LinkButton lnkEditButton = (LinkButton)grdAgentSpecficProperty.Rows[0].FindControl("lnkEditButton");
                    lnkEditButton.CommandArgument = e.Row.RowIndex.ToString();

but that gives me index out of range

Thanks,

R8VI
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question