473,624 Members | 2,005 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting values from user control added to DataGrid

I created an user control (.ascx file) with a DropDownList (DDL) with the
following code behide:

public string Selected_dept_v alue()
{
string dept_value = dept_dropdown.S electedValue;
return dept_value;
}

All the values were added via the visual interface.

I have droped this on my .aspx page and everything works fine. When making
additions to my datagrid.

<uc1:department _dropdown id="Department_ dropdown1"
runat="server"> </uc1:department_ dropdown>

The problem is when I am editing my datagrid.

Where I have:

<asp:templateco lumn HeaderText="Dep artment">
<itemtemplate >
<%# DataBinder.Eval (Container.Data Item, "Emp_Department ") %>
</itemtemplate>
<edititemtempla te>
<uc1:department _dropdown id="Department_ dropdown2" runat="server">
</uc1:department_ dropdown>
</edititemtemplat e>

The DDL displays fine, but I cannot get the values when clicking update:

Here is the error and code behind that it is failing on:

Error: Object reference not set to an instance of an object <-- However I
have the following:

protected Department_drop down Department_drop down2;

Code:
str_emp_dept =
((DropDownList) e.Item.FindCont rol(Department_ dropdown2.Selec ted_dept_value( ))).SelectedVal ue;
Nov 19 '05 #1
3 1268
And the anwser is:

In the code behind:
str_emp_dept =
Convert.ToStrin g(((Department_ dropdown)e.Item .FindControl("D epartment_dropd own2")).Selecte d_dept_value()) ;

WHOOOOOOHOOOOOO O!!!!!!!!!!!!!!
"Moojjoo" wrote:
I created an user control (.ascx file) with a DropDownList (DDL) with the
following code behide:

public string Selected_dept_v alue()
{
string dept_value = dept_dropdown.S electedValue;
return dept_value;
}

All the values were added via the visual interface.

I have droped this on my .aspx page and everything works fine. When making
additions to my datagrid.

<uc1:department _dropdown id="Department_ dropdown1"
runat="server"> </uc1:department_ dropdown>

The problem is when I am editing my datagrid.

Where I have:

<asp:templateco lumn HeaderText="Dep artment">
<itemtemplate >
<%# DataBinder.Eval (Container.Data Item, "Emp_Department ") %>
</itemtemplate>
<edititemtempla te>
<uc1:department _dropdown id="Department_ dropdown2" runat="server">
</uc1:department_ dropdown>
</edititemtemplat e>

The DDL displays fine, but I cannot get the values when clicking update:

Here is the error and code behind that it is failing on:

Error: Object reference not set to an instance of an object <-- However I
have the following:

protected Department_drop down Department_drop down2;

Code:
str_emp_dept =
((DropDownList) e.Item.FindCont rol(Department_ dropdown2.Selec ted_dept_value( ))).SelectedVal ue;

Nov 19 '05 #2
When you have a user control, declare it in the webform designer generated
code with all of your other controls. Make sure to name it exacltly the same
as your aspx page. Then you will be able to access it the exact same as you
would any other control.

OR -

You can just create an inherited dropdown control with the added field for
your selected department. Then you wouldn't have do a find control, it would
just automatically add itself to the designer generated code. As an added
bonus, you would see the dropdown in your designer instead of the generic
user control.
--
Staff Consultant II
Enterprise Web Services
Cardinal Solutions Group

Future Business Model
Loan Origination Services
National City Mortgage
"Moojjoo" wrote:
I created an user control (.ascx file) with a DropDownList (DDL) with the
following code behide:

public string Selected_dept_v alue()
{
string dept_value = dept_dropdown.S electedValue;
return dept_value;
}

All the values were added via the visual interface.

I have droped this on my .aspx page and everything works fine. When making
additions to my datagrid.

<uc1:department _dropdown id="Department_ dropdown1"
runat="server"> </uc1:department_ dropdown>

The problem is when I am editing my datagrid.

Where I have:

<asp:templateco lumn HeaderText="Dep artment">
<itemtemplate >
<%# DataBinder.Eval (Container.Data Item, "Emp_Department ") %>
</itemtemplate>
<edititemtempla te>
<uc1:department _dropdown id="Department_ dropdown2" runat="server">
</uc1:department_ dropdown>
</edititemtemplat e>

The DDL displays fine, but I cannot get the values when clicking update:

Here is the error and code behind that it is failing on:

Error: Object reference not set to an instance of an object <-- However I
have the following:

protected Department_drop down Department_drop down2;

Code:
str_emp_dept =
((DropDownList) e.Item.FindCont rol(Department_ dropdown2.Selec ted_dept_value( ))).SelectedVal ue;

Nov 19 '05 #3
Michael can you go into more detail on naming my user control the same as the
..aspx page?

Also, can you go into more detail on inherited dropdown control? Also did
you understand my question I was placing the UserControl inside of a datagrid?

"Michael Baltic" wrote:
When you have a user control, declare it in the webform designer generated
code with all of your other controls. Make sure to name it exacltly the same
as your aspx page. Then you will be able to access it the exact same as you
would any other control.

OR -

You can just create an inherited dropdown control with the added field for
your selected department. Then you wouldn't have do a find control, it would
just automatically add itself to the designer generated code. As an added
bonus, you would see the dropdown in your designer instead of the generic
user control.
--
Staff Consultant II
Enterprise Web Services
Cardinal Solutions Group

Future Business Model
Loan Origination Services
National City Mortgage
"Moojjoo" wrote:
I created an user control (.ascx file) with a DropDownList (DDL) with the
following code behide:

public string Selected_dept_v alue()
{
string dept_value = dept_dropdown.S electedValue;
return dept_value;
}

All the values were added via the visual interface.

I have droped this on my .aspx page and everything works fine. When making
additions to my datagrid.

<uc1:department _dropdown id="Department_ dropdown1"
runat="server"> </uc1:department_ dropdown>

The problem is when I am editing my datagrid.

Where I have:

<asp:templateco lumn HeaderText="Dep artment">
<itemtemplate >
<%# DataBinder.Eval (Container.Data Item, "Emp_Department ") %>
</itemtemplate>
<edititemtempla te>
<uc1:department _dropdown id="Department_ dropdown2" runat="server">
</uc1:department_ dropdown>
</edititemtemplat e>

The DDL displays fine, but I cannot get the values when clicking update:

Here is the error and code behind that it is failing on:

Error: Object reference not set to an instance of an object <-- However I
have the following:

protected Department_drop down Department_drop down2;

Code:
str_emp_dept =
((DropDownList) e.Item.FindCont rol(Department_ dropdown2.Selec ted_dept_value( ))).SelectedVal ue;

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2008
by: Balamurukan | last post by:
How to retrive property values from our own property window
2
4774
by: adbarnet | last post by:
Hi, I'm a C++ developer coming fresh to c# for GUI development. For the project I'm working on, I need a specialised control (a treeview derivative) which would be very useful in other applications I might need to write. Back in my day ;-) I would have written a user control for use from within VB, which I could still do, however - I also have the (more appealing from my perspective) option of deriving a control from the .NET base...
2
2027
by: Colin McGuigan | last post by:
This is a translation of an ASP page to ASP.Net. First, the background: The goal is to have a grid of different settings for the application -- think something along the lines of the Property Page for a control. You have two columns -- the first column is a simple caption, and the second column can be one of a number of controls (textbox, checkbox, dropdownlist, etc) for each row. So row #1 might have a textbox in the second column,...
2
2834
by: Alex | last post by:
Hi all, I'm writing a small web application which searches a database based on a date field, and populates a datagrid control with the results. The datagrid control has selection buttons added to it to view additional details about the selected result (a second database query is triggered). I want this second query to pop up in a new window, the way it would if I used "window.open" in javascript. I've added a function in the
0
1439
by: Gujju | last post by:
Hi all, Have a question from the following post to create user control in a Datagrid.... http://www.dotnet247.com/247reference/msgs/45/225337.aspx I have a question.... I can create the User control in the Datagrid... and that is a run time user control in the datagrid.. without using the <templatecolumn> in the datagrid... and on ItemCreated Event i create the
1
1385
by: Arjen Hoekstra | last post by:
Hello, I've got a datagrid with a textbox in each cell. I've also two buttons, one to add a row to the datagrid and one to delete a row. A user can type data into textboxes and then submit it to a database (by clicking on a submit button). The problem is that every time, the "add row" or "delete row" button is clicked, the textbox values in the datagird are emptied, because when the page postbacks it gets the latest datatable from a...
4
5033
by: Larry Grady | last post by:
Anyone up for a challenge? I've been struggling with this for a few days and was hoping someone could help me. Pouring through all the messageboards I just can't find the solution. We have a GridView that needs to be dynamically designed, depending on what collection of fields our uses want to edit for their product data. We have 400+ fields of information per product so they're selecting a subset of those fields to edit.
4
1792
by: Server Control | last post by:
Hi, I have a datagrid(within a user control) that has label controls. I have added hidden fields in the datagrid alongwitht the label control. I do some client side editing with javascript and somehow want to reset the label value through javascript? I could grab the id of the row that had the label in it (now converted to a span at client side) by accessing the corresponding hidden field with it. var hdnLabel =...
3
3909
by: Mark Rae | last post by:
Hi, Just a general quickie on setting properties of user controls from the parent form. Let's say I have a user control called note.ascx which displays a datagrid. That datagrid is populated according to an integer variable in the ViewState of the parent form. The code behind (still in v1.1) of the user control contains the following:
0
8236
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
8173
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8335
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
7159
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...
0
5563
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
4079
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...
0
4174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2606
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1482
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.