Link to home
Start Free TrialLog in
Avatar of tia_kamakshi
tia_kamakshiFlag for United Arab Emirates

asked on

Datagrid, ItemDataBound find control

Hi,

I am working on C#, ASP.net 1.1

I have used Datagrid, In datagrid I have button btnRemove.

On my ItemDataBound, I am not finding btnRemove, it always is null why???

can anyone help me

Below is my code:

private void grdProducts_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
      Button btnRemove = (Button)e.Item.FindControl("btnRemove");                  

      string strContentProductID = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "contentProductID"));

      if(strContentProductID == null && btnRemove != null)
      {
            btnRemove.Visible = false;
      }
}



<asp:DataGrid id="grdProducts" runat="server" ItemStyle-CssClass="adminTableCell" HeaderStyle-CssClass="adminTableCategoryHeader"
      CssClass="adminTable" AutoGenerateColumns="False">
      <ItemStyle CssClass="adminTableCell"></ItemStyle>
      <HeaderStyle CssClass="adminTableCategoryHeader"></HeaderStyle>
      <Columns>
            <asp:BoundColumn DataField="Np4uExternalPartNumber" HeaderText="Np4uExternalPartNumber">
                  <HeaderStyle Width="300px"></HeaderStyle>
                  <ItemStyle HorizontalAlign="Left"></ItemStyle>
            </asp:BoundColumn>
            <asp:BoundColumn DataField="ShortDesc" HeaderText="Short Desc">
                  <HeaderStyle Width="300px"></HeaderStyle>
                  <ItemStyle HorizontalAlign="Left"></ItemStyle>
            </asp:BoundColumn>
            <asp:BoundColumn DataField="PageTitle" HeaderText="Page Title">
                  <HeaderStyle Width="300px"></HeaderStyle>
                  <ItemStyle HorizontalAlign="Left"></ItemStyle>
            </asp:BoundColumn>
            <asp:TemplateColumn HeaderText="Read Only">
                  <HeaderStyle HorizontalAlign="Center" Width="120px"></HeaderStyle>
                  <ItemStyle HorizontalAlign="Center"></ItemStyle>
                  <ItemTemplate>
                        <asp:Button runat="server" ID="btnAdd" Text='Add'></asp:Button>
                        <asp:Button runat="server" ID="btnRemove" Text='Remove'></asp:Button>
                  </ItemTemplate>
            </asp:TemplateColumn>
      </Columns>
</asp:DataGrid>


ASKER CERTIFIED SOLUTION
Avatar of crazyman
crazyman
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tia_kamakshi

ASKER

Thanks allot