Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have a delete linkbutton inside gridview and there are confirm message while user click on button. but there are some condition when my button disable and i want do not show confirmation box when my button is disable.

my java script function is

C#
function DeleteConfirmation()
    {
         if (confirm("Are you sure,you want to delete selected record ?")==true)
         return true;
         else
         return false;
    }




my gridview


XML
<asp:GridView ID="grdShowProduct" runat="server"
            AutoGenerateColumns="false" onrowcommand="grdShowProduct_RowCommand"
            onrowdatabound="grdShowProduct_RowDataBound" Width="100%"
            AutoGenerateEditButton="true"  AutoGenerateDeleteButton="false"
            onrowcancelingedit="grdShowProduct_RowCancelingEdit"
            onrowediting="grdShowProduct_RowEditing"
            onrowupdating="grdShowProduct_RowUpdating" >
            <HeaderStyle CssClass="headerGrd" />
                <AlternatingRowStyle CssClass="alternateRowGrd" />
                <EditRowStyle CssClass="editGrd" />
             <Columns>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:LinkButton ID="lnkDelete" OnClientClick="return DeleteConfirmation();" Text="Delete" CommandName="Remove" CommandArgument='<%# Bind("id") %>' runat="server" />
                    </ItemTemplate>
                </asp:TemplateField>

                 <asp:TemplateField>
                    <ItemTemplate>
                        <asp:LinkButton ID="lnkMoreDetail" CssClass="MoreDetail" Text="Lots&nbsp;Detail" CommandName="show" CommandArgument='<%# Bind("id") %>' runat="server" />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:LinkButton ID="lnkMoreDetail" CssClass="MoreDetail" Text="Lots&nbsp;Detail" CommandName="show" CommandArgument='<%# Bind("id") %>' runat="server" />
                    </EditItemTemplate>
                 </asp:TemplateField>

                 <asp:TemplateField HeaderText="Date" >
                    <ItemTemplate>
                        <asp:Label ID="lblId" Text='<%# Bind("id") %>' Visible="false" runat="server" />
                        <asp:Label ID="lblGrdDate" runat="server" Text='<%# Eval("date","{0:dd-MMM-yyyy}") %>'></asp:Label>
                    </ItemTemplate>
                 </asp:TemplateField>

                 <asp:TemplateField HeaderText="Order Code" >
                    <ItemTemplate>
                      <asp:Label ID="lblGrdOrderCode" runat="server" Text='<%# Bind("orderCode") %>' ClientIDMode="Static" ></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                     <asp:TextBox runat="server" ID="txtGrdOrderCode" Text='<%# Bind("orderCode") %>' />
                     <asp:FilteredTextBoxExtender ID="fltGrdOrderCode1" FilterType="UppercaseLetters, LowercaseLetters, Custom" TargetControlID="txtGrdOrderCode" ValidChars=" -" runat="server" />
                     <asp:RequiredFieldValidator ID="reqGrdOrderCode1" ControlToValidate="txtGrdOrderCode" CssClass="validationError" runat="server" Display="Dynamic"  ErrorMessage="Order Code cannot be empty." ValidationGroup="Update">*</asp:RequiredFieldValidator>
                    </EditItemTemplate>
                  </asp:TemplateField>

                    <asp:TemplateField HeaderText="Color" >
                        <ItemTemplate>
                      <asp:Label ID="lblGrdColor" runat="server" Text='<%# Bind("color") %>' ></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                    <asp:Label ID="lblGrdColor" runat="server" Text='<%# Bind("color") %>' Visible="false" ></asp:Label>
                    <%--<asp:Label ID="lblColorId" Text='<%# Bind("colorId") %>' Visible="false" runat="server" ClientIDMode="Static" />--%>

                    <asp:DropDownList ID="ddlColor1" runat="server"  Width="175px" ></asp:DropDownList>
                    <asp:RequiredFieldValidator ID="reqColorShw" ControlToValidate="ddlColor1" CssClass="validationError" runat="server" Display="Dynamic" Text="*" ErrorMessage="*" ValidationGroup="Update"></asp:RequiredFieldValidator>
                    </EditItemTemplate>
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="Quantity" >
                     <ItemTemplate>
                       <asp:Label ID="lblGrdQuantity" runat="server" Text='<%# Bind("quantity") %>' ></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="txtQuantity1" runat="server" Text='<%# Bind("quantity") %>' BorderStyle="none" BorderWidth="0px"></asp:TextBox>
                        <asp:FilteredTextBoxExtender ID="fltQuantityShw" FilterType="Numbers" TargetControlID="txtQuantity1" runat="server" />
                        <asp:RequiredFieldValidator ID="reqQuantityShw" ControlToValidate="txtQuantity1" CssClass="validationError"  runat="server" Display="Dynamic" Text="*" ErrorMessage="*" ValidationGroup="Update"></asp:RequiredFieldValidator>
                    </EditItemTemplate>
                    </asp:TemplateField>


                    <asp:TemplateField HeaderText="Quantity per Lot" >
                        <ItemTemplate>
                    <asp:Label ID="lblGrdQuantityPrLot" runat="server" Text='<%# Bind("quantityPrLot") %>' ></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="txtQuantityPrLot1" runat="server" Text='<%# Bind("quantityPrLot") %>' BorderStyle="none" CssClass="QuntLot" BorderWidth="0px" ></asp:TextBox>
                        <asp:FilteredTextBoxExtender ID="fltQuantityPrLotShw" FilterType="Numbers" TargetControlID="txtQuantityPrLot1" runat="server" />
                        <asp:RequiredFieldValidator ID="reqQuantityPrLotShw" ControlToValidate="txtQuantityPrLot1" CssClass="validationError" runat="server" Display="Dynamic" Text="*" ErrorMessage="*" ValidationGroup="Update"></asp:RequiredFieldValidator>
                        </EditItemTemplate>
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="Total Lots">
                     <ItemTemplate>
                        <asp:Label ID="txtTotalLots1" runat="server" Text='<%# Bind("totalLots") %>' ></asp:Label>
                     </ItemTemplate>
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="Origin" >
                     <ItemTemplate>
                       <asp:Label ID="lblGrdOrigin" runat="server" Text='<%# Bind("origin") %>' ></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:Label ID="lblGrdOrigin" runat="server" Text='<%# Bind("origin") %>' Visible="false"></asp:Label>
                       <%-- <asp:Label ID="lblOriginId" Text='<%# Bind("OriginId") %>' Visible="false" runat="server" />--%>
                        <asp:DropDownList ID="ddlOrigin1" runat="server"  Width="175px"  ></asp:DropDownList>
                        <asp:RequiredFieldValidator ID="reqOriginShw" ControlToValidate="ddlOrigin1" CssClass="validationError" runat="server" Display="Dynamic" Text="*" ErrorMessage="*" ValidationGroup="Update"></asp:RequiredFieldValidator>
                    </EditItemTemplate>
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="Grade" >
                    <ItemTemplate>
                    <asp:Label ID="lblGrdGrade" runat="server" Text='<%# Bind("gradeId") %>' ></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                    <asp:Label ID="lblGrdGrade" runat="server" Text='<%# Bind("gradeId") %>' Visible="false" ></asp:Label>
                        <asp:DropDownList ID="ddlGrade1" runat="server"  Width="175px" >
                        <asp:ListItem Value="0" Text="Select Grade"></asp:ListItem>
                        <asp:ListItem Value="1" Text="1"></asp:ListItem>
                        <asp:ListItem Value="2" Text="2"></asp:ListItem>
                        <asp:ListItem Value="3" Text="3"></asp:ListItem>
                        <asp:ListItem Value="4" Text="4"></asp:ListItem>
                        <asp:ListItem Value="5" Text="5"></asp:ListItem>
                        <asp:ListItem Value="6" Text="6"></asp:ListItem>
                        <asp:ListItem Value="7" Text="7"></asp:ListItem>
                        <asp:ListItem Value="8" Text="8"></asp:ListItem>
                        <asp:ListItem Value="9" Text="9"></asp:ListItem>
                        <asp:ListItem Value="10" Text="10"></asp:ListItem>
                        </asp:DropDownList>
                        <asp:RequiredFieldValidator ID="reqGradeShw" ControlToValidate="ddlGrade1" CssClass="validationError" runat="server" Display="Dynamic" Text="*" ErrorMessage="*" ValidationGroup="Update"></asp:RequiredFieldValidator>
                        </EditItemTemplate>
                    </asp:TemplateField>


                    <asp:TemplateField HeaderText="D.M." >
                    <ItemTemplate>
                    <asp:Label ID="lblGrdDM" runat="server" Text='<%# Bind("DM") %>' ></asp:Label>
                    </ItemTemplate>
                     <EditItemTemplate>
                        <asp:TextBox ID="txtDM1" runat="server" Text='<%# Bind("DM") %>' BorderStyle="none" BorderWidth="0px"></asp:TextBox>
                        <asp:FilteredTextBoxExtender ID="fltDMShw" FilterType="Numbers" TargetControlID="txtDM1"  runat="server" />
                        <asp:RequiredFieldValidator ID="reqDMShw" ControlToValidate="txtDM1" CssClass="validationError" runat="server" Display="Dynamic" Text="*" ErrorMessage="*" ValidationGroup="Update"></asp:RequiredFieldValidator>
                      </EditItemTemplate>
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="Process" >
                     <ItemTemplate>
                      <asp:Label ID="lblGrdProcess" runat="server" Text='<%# Bind("IsManual") %>' ></asp:Label>
                     </ItemTemplate>
                    <EditItemTemplate>
                    <asp:Label ID="lblGrdProcess" runat="server" Text='<%# Bind("IsManual") %>' Visible="false" ></asp:Label>
                        <asp:DropDownList ID="ddlProcess1" runat="server" >
                            <asp:ListItem Value="-1" Text="Select Process"></asp:ListItem>
                            <asp:ListItem Value="0" Text="Manual"></asp:ListItem>
                            <asp:ListItem Value="1" Text="Standard"></asp:ListItem>
                        </asp:DropDownList>
                        <asp:RequiredFieldValidator ID="reqProcessShw" ControlToValidate="ddlProcess1" InitialValue="-1" runat="server" CssClass="validationError" Display="Dynamic" Text="Please,Select any process." ErrorMessage="Please,Select any process." ValidationGroup="Update">*</asp:RequiredFieldValidator>
                    </EditItemTemplate>
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="Status" >
                    <ItemTemplate>
                     <asp:Label ID="lblGrdStatus" runat="server" Text='<%# Bind("IsCompleted") %>' ></asp:Label>
                    </ItemTemplate>
                   </asp:TemplateField>
            </Columns>
        </asp:GridView>



when Status field is Waiting my button will be enable else button will be disable


c# code

gridview rowdataboud code

LinkButton lnkDelete = (LinkButton)e.Row.FindControl("lnkDelete");
if (lblGrdStatus.Text != "Waiting")
{
lnkDelete.Enabled = false;

}

please tell me how to solve this problem

thanks in advance
Posted
Updated 26-Apr-13 0:03am
v2
Comments
kk2014 26-Apr-13 6:51am    
i think it will give
'Object reference not set to an instance of an object.' error.
because when u click on link button and press yes in your confirmation msg it will go to row data bound when it finds the button and check condition
if (lblGrdStatus.Text != "Translation")
{
lnkDelete.Enabled = false;
}
but have no text so will result in error.

Add below code with your code at code behind hope it will work

C#
LinkButton lnkDelete = (LinkButton)e.Row.FindControl("lnkDelete");
if (lblGrdStatus.Text != "Waiting")
{
lnkDelete.Enabled = false;
LinkButton1.OnClientClick = "return false;";
}
 
Share this answer
 
Comments
ashok luhach 26-Apr-13 8:58am    
thanks Parveen sir its work for me
In asp:linkbutton if it is disable then it wil apply this
HTML
class="aspNetDisabled"
. so you just need to check on that javascript click function that clicked source is have this class attach or not?. this will solve your problem.
 
Share this answer
 
Comments
ashok luhach 26-Apr-13 6:40am    
please give me example how to check this cssclass in javacscript function

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900