473,387 Members | 1,347 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

FindControl datagrid

I want to find a control in a datagrid and use the code in Page_load. Can someone pls help me.
Aug 2 '07 #1
4 2593
Frinavale
9,735 Expert Mod 8TB
I want to find a control in a datagrid and use the code in Page_load. Can someone pls help me.
Hi HenryChong,

I have moved your question to the .NET forum. The .NET Articles section is reserved for articles that are purely informational; like "how-tos" etc. The .NET Forum is the place for your questions. In the future please post your questions here (Blue Menu Along the Top: Forums->.NET).

As for your question:
I'm a bit confused about what you are trying to do exactly?
Could you please explain the problem you are trying to solve so that we can help you better?

Thanks!

-Frinny
Aug 2 '07 #2
I want to find a control in a datagrid and use the code in Page_load. Can someone pls help me.
If u want to find a control like check box then take a variable of type checkbox and then use foreach loop for getting the control
Aug 2 '07 #3
I want to find a dropdownlist control in a datagrid (named dgDestinations) and then i want to make the dropdownlist visible in Page_load. How can i access the control in Page_load? It works if i find a control in an itemcommand or a dropdownlist control in a page. But not if i want to find a control (in a datagrid) in Page_load.

Here's the code:
Expand|Select|Wrap|Line Numbers
  1. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  2.  
  3. 'This works too
  4. Dim ddltest As System.Web.UI.WebControls.DropDownList = CType(FindControl("ddlBulkoutloadingposition"), DropDownList)
  5. ddltest.Visible = False
  6.  
  7. 'This doesn't work.
  8. Dim ddlbox As System.Web.UI.WebControls.DropDownList = CType(dgDestinations.FindControl("ddlNewBox"), DropDownList)
  9. ddlbox.Visible = False
  10.  
  11. End Sub
The code below works.
Expand|Select|Wrap|Line Numbers
  1. Protected Sub dgDestinations_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles dgDestinations.ItemCommand
  2.  
  3.  
  4.  
  5. Dim ddlNewBox As System.Web.UI.WebControls.DropDownList 
  6. ddlNewBox = CType(e.Item.FindControl("ddlNewBox"), DropDownList)
  7. ddlNewBox.Visible = True
  8.  
  9. End Sub
Aug 2 '07 #4
I already tried, but also didn't work:
Expand|Select|Wrap|Line Numbers
  1. Dim dgItem As DataGridItem
  2. Dim ddltest As DropDownList
  3. For Each dgItem In dgDestinations.Items
  4.         ddltest = CType(dgDestinations.FindControl("ddlNewBox"), DropDownList)
  5.  
  6.         If ddltest Is Nothing Then
  7.         Else
  8.              ddltest.Visible = True
  9.         End If
  10.  
  11. Next
  12.  
Aug 2 '07 #5

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

Similar topics

4
by: Sid | last post by:
Hi, I am trying to use the FindControl method to find a HTML Select control I have in my Datagrid. The syntax I am using is Dim obj As HTMLSelect Dim str As String obj =...
1
by: Mike Speak | last post by:
On my page_load, I am populating a Datagrid through the normal manner (which works) before attempting to pick out the items in one column to use in another part of my page. This is all within...
1
by: tshad | last post by:
I am using sample code from C# and am trying to convert it to VB.Net in my aspx page. This works in C#: DataGrid oGrid = (DataGrid)oItem.FindControl("DataGrid1"); I have tried all kinds of...
0
by: BG | last post by:
i am thinking that creating datagrid at design time will save me a lot of time when creating programs. however, i ran into a brick wall. i created a template column at design time. i learned...
3
by: MattB | last post by:
I have a datagrid that has some controls (TextBoxes and DropDownLists) that are created dynamically at runtime. I've got the generation working ok, but now I need to see what was entered or...
2
by: MattB | last post by:
I've got some controls (mostly textboxes for now) that get created at runtime in a DataGrid. I create them using the OnItemDataBound event. I realize this isn't ideal, but I'm trying to see if I...
10
by: Terry Olsen | last post by:
I've got a datagrid set up to display data. I've also got an Edit,Update,Cancel column set up to allow editing of data. I've got a DropDownList (ID="ddl3")in the EditItemTemplate for a certain...
2
by: zambizzi | last post by:
....I can't seem to get my hands on a control I'm loading in an editable datagrid. Here's my datagrid control: <asp:datagrid id="GLRulesGrid" runat="server" autogeneratecolumns="False"...
1
by: Jim Bayers | last post by:
I get this error: System.NullReferenceException: Object reference not set to an instance of an object. And this is the subroutine that throws it: Protected Sub DataUpdate(ByVal Sender As...
11
by: =?Utf-8?B?TWlrZSBDb2xsaW5z?= | last post by:
I am trying to get the text of an item in a GridView, but am doing something wrong. Can someone help me with the correct C# statement I need? Below is my GridView and my attempt to get the control....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.