Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 717
  • Last Modified:

gridview edit button

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
R8VI
Asked:
R8VI
  • 7
  • 5
1 Solution
 
markmiddlemistCommented:
Are you seeing anything come up in the error console, either on loading the page, or on clicking the link?
0
 
R8VIAuthor Commented:
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
 
markmiddlemistCommented:
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
R8VIAuthor Commented:
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
 
markmiddlemistCommented:
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
 
R8VIAuthor Commented:
Hi,

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

Thanks,

R8vi
0
 
markmiddlemistCommented:
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
 
R8VIAuthor Commented:
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
 
R8VIAuthor Commented:
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
 
R8VIAuthor Commented:
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
 
markmiddlemistCommented:
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
 
R8VIAuthor Commented:
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now