Hi,
I am create web application.In this application i am use CommandField in datagridview. when i am search record there is no record in datagrid view then i call empty function. In this function i want to disable CommandField but how to disable this CommandField.
<asp:GridView ID="grdItemStatus" runat="server" AllowPaging="True"
AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333"
GridLines="None" onpageindexchanging="grdItemStatus_PageIndexChanging"
onrowcancelingedit="grdItemStatus_RowCancelingEdit"
onrowcommand="grdItemStatus_RowCommand" onrowcreated="grdItemStatus_RowCreated"
onrowdatabound="grdItemStatus_RowDataBound"
onrowdeleting="grdItemStatus_RowDeleting"
onrowediting="grdItemStatus_RowEditing"
onrowupdating="grdItemStatus_RowUpdating"
onselectedindexchanging="grdItemStatus_SelectedIndexChanging" ShowFooter="True" PageSize="15">
<PagerTemplate>
Record Per Page
<asp:TextBox ID="txtRecordPerPage" runat="server" AutoPostBack="true"
MaxLength="3" Width="30px" onkeypress="return checkOnlyNumber();"
ontextchanged="txtRecordPerPage_TextChanged" CssClass="TextBoxAll"></asp:TextBox>
Goto Page
<asp:DropDownList ID="ddlPageSelector" runat="server" AutoPostBack="true"
onselectedindexchanged="ddlPageSelector_SelectedIndexChanged">
</asp:DropDownList>
<asp:Button Text="<<" CommandName="Page" CommandArgument="First" runat="server"
ID="btnFirst" BackColor="White" Font-Bold="True" ToolTip="First" />
<asp:Button Text="<" CommandName="Page" CommandArgument="Prev" runat="server"
ID="btnPrevious" BackColor="White" Font-Bold="True" ToolTip="Previous" />
<asp:Button Text=">" CommandName="Page" CommandArgument="Next" runat="server"
ID="btnNext" BackColor="White" Font-Bold="True" ToolTip="Next" />
<asp:Button Text=">>" CommandName="Page" CommandArgument="Last" runat="server"
ID="btnLast" BackColor="White" Font-Bold="True" ToolTip="Last" />
</PagerTemplate>
<RowStyle BackColor="White" ForeColor="#333333" />
<Columns>
<asp:TemplateField HeaderText="Serial No.">
<EditItemTemplate>
<asp:Label ID="lblSerialNo" runat="server" Text='<%# Container.DataItemIndex + 1 %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblSerialNo" runat="server" Text='<%# Container.DataItemIndex + 1 %>'></asp:Label>
</ItemTemplate>
<HeaderStyle CssClass="LableDisp" HorizontalAlign="Center"
VerticalAlign="Middle" Width="70px" />
<ItemStyle CssClass="LableGrid" HorizontalAlign="Center" VerticalAlign="Middle"
Width="70px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Status Code" Visible="false">
<EditItemTemplate>
<asp:Label ID="lblStatusCode" runat="server" Text='<%# Bind("StatusCode") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblStatusCode" runat="server" Text='<%# Bind("StatusCode") %>'></asp:Label>
</ItemTemplate>
<%--<FooterTemplate>
<asp:TextBox ID="txtStatusCode" runat="server" CssClass="TextBoxAll" Width="130px"></asp:TextBox>
</FooterTemplate>
<HeaderTemplate>
<asp:Label ID="Label1" runat="server" Text="Status Code"></asp:Label>
<br />
<asp:TextBox ID="txtStatusCode" runat="server" CssClass="TextBoxAll"
Width="130px" AutoPostBack="True" ontextchanged="txtStatusCode_TextChanged"></asp:TextBox>
</HeaderTemplate>--%>
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="150px" CssClass="LableDisp"/>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="150px" CssClass="LableGrid"/>
</asp:TemplateField>
<asp:TemplateField HeaderText="Desc">
<EditItemTemplate>
<asp:DropDownList ID="ddlItemDesc" runat="server" CssClass="ComboBox1">
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("StatusDesc") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlItemDesc" runat="server" CssClass="ComboBox1">
</asp:DropDownList>
</FooterTemplate>
<HeaderTemplate>
<asp:Label ID="Label2" runat="server" Text="Desc"></asp:Label>
<br />
<asp:TextBox ID="txtStatusDesc" runat="server" CssClass="TextBoxAll"
Width="230px" AutoPostBack="True" ontextchanged="txtStatusDesc_TextChanged"></asp:TextBox>
</HeaderTemplate>
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="270px" CssClass="LableDisp"/>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="270px" CssClass="LableGrid"/>
</asp:TemplateField>
<%-- <asp:TemplateField Visible="False">
<EditItemTemplate>
<asp:Label ID="lblItemStatusId" runat="server" Text='<%# Bind("ItemStatusId") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblItemStatusId" runat="server" Text='<%# Bind("ItemStatusId") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>--%>
<asp:TemplateField HeaderText="" ShowHeader="False" HeaderStyle-HorizontalAlign="Left">
<%--<EditItemTemplate>
<asp:LinkButton ID="lbkUpdate" runat="server" CausesValidation="True"
CommandName="Update" Text="Update" Font-Bold="True" ForeColor="Black"></asp:LinkButton>
<asp:LinkButton ID="lnkCancel" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel" Font-Bold="True" ForeColor="Black"></asp:LinkButton>
</EditItemTemplate> --%>
<FooterTemplate>
<asp:LinkButton ID="lnkAdd" runat="server" CausesValidation="False"
CommandName="Insert" Text="Insert" Font-Bold="True" ForeColor="White"></asp:LinkButton>
</FooterTemplate>
<%-- <ItemTemplate>
<asp:LinkButton ID="lnkEdit" runat="server" CausesValidation="False"
CommandName="Edit" Text="Edit" Font-Bold="True" ForeColor="Black"></asp:LinkButton>
</ItemTemplate> --%>
<HeaderStyle HorizontalAlign="Left" CssClass="LableDisp"/>
<ItemStyle CssClass="LableGrid"/>
</asp:TemplateField>
<asp:CommandField HeaderText="Delete" ControlStyle-Font-Bold="true" ButtonType="Link" ShowDeleteButton="True" ShowHeader="True" />
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
private void ShowEmptyGrid()
{
try
{
lblRecordCount.Text = "0";
lblMsg.Text = "No Record Found";
DataTable dt = new DataTable();
dt.Columns.Add("SerialNo");
dt.Columns.Add("StatusCode");
dt.Columns.Add("StatusDesc");
DataRow dr = dt.NewRow();
dt.Rows.Add(dr);
grdItemStatus.DataSource = dt;
grdItemStatus.DataBind();
((Label)grdItemStatus.Rows[0].Cells[0].FindControl("lblSerialNo")).Text = "";
LinkButton lnkEdit = (LinkButton)grdItemStatus.Rows[0].Cells[4].FindControl("lnkEdit");
lnkEdit.Visible = false;
}
catch (Exception)
{
}
}