hi all...
does anyone know how we can disable a button in a grid view when neede???
i have grid that willdisplay some database data...
it also has a button...and i need it enabled or disabled depending upon the
value in another cell in the grid...how can i access that button and make it disabled...
please help...
thanx and regards...
sand...
OK, I assume that you use ASP.NET 2003 with C#.
You can manage the grid's controls at grid databound event.
see this sample,
I Fill dataset11 with Categories table from Northwind database.
I Bind dataset11 to datagrid1.
AT HTML........
-
<asp:DataGrid id=DataGrid1 style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 8px" runat="server" Width="464px" DataSource="<%# dataSet11 %>" DataKeyField="CategoryID" DataMember="Categories" AutoGenerateColumns="False">
-
<Columns>
-
<asp:BoundColumn DataField="CategoryID" SortExpression="CategoryID" HeaderText="CategoryID"></asp:BoundColumn>
-
<asp:BoundColumn DataField="CategoryName" SortExpression="CategoryName" HeaderText="CategoryName"></asp:BoundColumn>
-
<asp:BoundColumn DataField="Description" SortExpression="Description" HeaderText="Description"></asp:BoundColumn>
-
<asp:TemplateColumn>
-
<ItemTemplate>
-
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
-
</ItemTemplate>
-
</asp:TemplateColumn>
-
</Columns>
-
</asp:DataGrid>
-
AT CS...
-
private void Page_Load(object sender, System.EventArgs e)
-
{
-
sqlDataAdapter1.Fill(dataSet11);
-
DataGrid1.DataBind();
-
}
-
-
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
-
{
-
if ((e.Item.ItemType == ListItemType.Item) ||
-
(e.Item.ItemType == ListItemType.AlternatingItem) ||
-
(e.Item.ItemType == ListItemType.SelectedItem))
-
{
-
decimal ID= decimal.Parse (((DataRowView)e.Item.DataItem)["CategoryID"].ToString());
-
if(ID<5)
-
((Button)e.Item.FindControl("Button1")).Enabled = false;
-
}
-
}
-
Hope this help your requirement.
<X>