473,698 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

disable select button in a gridview...

97 New Member
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...
Jan 19 '07 #1
3 9751
snowwwolf
28 New Member
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........
Expand|Select|Wrap|Line Numbers
  1. <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">
  2.     <Columns>
  3.         <asp:BoundColumn DataField="CategoryID" SortExpression="CategoryID" HeaderText="CategoryID"></asp:BoundColumn>
  4.         <asp:BoundColumn DataField="CategoryName" SortExpression="CategoryName" HeaderText="CategoryName"></asp:BoundColumn>
  5.         <asp:BoundColumn DataField="Description" SortExpression="Description" HeaderText="Description"></asp:BoundColumn>
  6.         <asp:TemplateColumn>
  7.             <ItemTemplate>
  8.                 <asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
  9.             </ItemTemplate>
  10.         </asp:TemplateColumn>
  11.     </Columns>
  12. </asp:DataGrid>
  13.  
AT CS...
Expand|Select|Wrap|Line Numbers
  1. private void Page_Load(object sender, System.EventArgs e)
  2. {
  3.     sqlDataAdapter1.Fill(dataSet11);
  4.     DataGrid1.DataBind();
  5. }
  6.  
Expand|Select|Wrap|Line Numbers
  1. private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
  2. {
  3.     if ((e.Item.ItemType == ListItemType.Item) ||
  4.         (e.Item.ItemType == ListItemType.AlternatingItem) ||
  5.         (e.Item.ItemType == ListItemType.SelectedItem))
  6.     {
  7.         decimal ID= decimal.Parse (((DataRowView)e.Item.DataItem)["CategoryID"].ToString());
  8.         if(ID<5)
  9.             ((Button)e.Item.FindControl("Button1")).Enabled = false;
  10.     }
  11. }
  12.  
Hope this help your requirement.

<X>
Jan 20 '07 #2
sandeepk84
97 New Member
Thanx a lot 4 ur reply snowwwolf....
but i have another requirement like,
can i have access to a cell in the grid view at d time of databinding???
means at the time of databinding i need to add a button to d grid dynamically based on d value of an existing cell in d grid...
And am having ASP.NET 2005...
Thanx and regards...
sand...
Jan 20 '07 #3
snowwwolf
28 New Member
Thanx a lot 4 ur reply snowwwolf....
but i have another requirement like,
can i have access to a cell in the grid view at d time of databinding???
means at the time of databinding i need to add a button to d grid dynamically based on d value of an existing cell in d grid...
And am having ASP.NET 2005...
Thanx and regards...
sand...

Sorry for my late reply, because of my weekend days.
try like this, may be it ok!
Expand|Select|Wrap|Line Numbers
  1. Button b;
  2. protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  3. {
  4.      if (e.Row.RowType == DataControlRowType.DataRow)
  5.      {
  6.          decimal id = Convert.ToDecimal(e.Row.Cells[0].Text);
  7.          if (id < 5)
  8.          {
  9.              b = new Button();
  10.              b.Text = "New Button";
  11.              e.Row.Cells[3].Controls.Add(b);
  12.          }
  13.      }
  14. }
  15.  

<X>
Jan 22 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
19062
by: misiek | last post by:
Hi all. I would like to know if it is possible to dynamically enable/disable row editing in GridView control in ASP.NET 2.0. I am asking because this feature should be enabled/disable depending on button, which was clicked by user. Thanks in advance, misiek
4
12891
by: Dabbler | last post by:
Is there a way to let the user select a gridview row by clicking anywhere in the row (e.g. on any column)? The gridview would be readonly and I would like to bring up a detailview of the row the user clicked on. Thanks.
6
10080
by: Terry | last post by:
Good morning! How do I determine which SELECT button was clicked in a GridView? The multiple SELECT buttons will be used for an application approval process. Thank you in advance for your support in this matter.
5
3152
by: Michael Fällgreen | last post by:
Hi, I have a search page with a textbox, button, gridview and a objectdatasource. It works great with one problem. When the page loads the first time the objectdatasource calls the select-method and because its bound to the textbox (search string) and the textbox is empty it display all records. This is not the way I wnat it to work - however I want the user to be able to make a blank search (and return all items). Can I "disable" the...
1
2714
by: keithb | last post by:
I have a GridView control that has a delete button (hyperlink) in one column. The datasource table contains a column that has a true/false indicator showing whether or not the record can be deleted. How can I enable/disable the delete button depending on the value of the indicator? Ideally, I would like to make the button invisible where a record cannot be deleted. Thanks, Keith
1
8602
by: Mike P | last post by:
How do you disable the edit button for selected rows in a gridview? Here is my button : <asp:CommandField ShowEditButton="True" ButtonType="Link" ShowCancelButton="True" UpdateText="Update" EditText="Edit" CancelText="Cancel" />
0
1804
by: Moneypenny | last post by:
Hi there, I have a Gridview control which has a dropdownlist in every row. The dropdowns are populated dynamically from a database (so the content is different in each row. There is also a select button for each row so that the the user can choose a row and the values will be added to a shopping cart. My problem is that the page loads fine and everything is showing as it should be. However, when I select a row the dropdownlist for that row...
3
7942
by: =?Utf-8?B?UGxhdGVyaW90?= | last post by:
I have link buttons in a Gridview that, depending on the value in another column (Not the Key column) will need to be disabled. For example, (Column2 has link buttons) Column1 Column2 Books 54 Videos 6 Audio 3
0
1250
by: =?Utf-8?B?R3JpZFZpZXcgTmV3Ymll?= | last post by:
I have a business requirement stating that when the Location Type is "C" the user should not be able to update the StoreNumber. So, when the user clicks the "edit" button in the GridView for a row, I need to check the value of location type for that row and then disable the control for the Store Number. The problem is I only need to do this when editing. I have put the logic in the DataRowBound event. In the RowEditing event a...
0
8675
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9029
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8897
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7729
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6521
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2331
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.