473,503 Members | 1,831 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_value()
{
string dept_value = dept_dropdown.SelectedValue;
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:templatecolumn HeaderText="Department">
<itemtemplate>
<%# DataBinder.Eval(Container.DataItem, "Emp_Department") %>
</itemtemplate>
<edititemtemplate>
<uc1:department_dropdown id="Department_dropdown2" runat="server">
</uc1:department_dropdown>
</edititemtemplate>

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_dropdown Department_dropdown2;

Code:
str_emp_dept =
((DropDownList)e.Item.FindControl(Department_dropd own2.Selected_dept_value())).SelectedValue;
Nov 19 '05 #1
3 1261
And the anwser is:

In the code behind:
str_emp_dept =
Convert.ToString(((Department_dropdown)e.Item.Find Control("Department_dropdown2")).Selected_dept_val ue());

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

public string Selected_dept_value()
{
string dept_value = dept_dropdown.SelectedValue;
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:templatecolumn HeaderText="Department">
<itemtemplate>
<%# DataBinder.Eval(Container.DataItem, "Emp_Department") %>
</itemtemplate>
<edititemtemplate>
<uc1:department_dropdown id="Department_dropdown2" runat="server">
</uc1:department_dropdown>
</edititemtemplate>

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_dropdown Department_dropdown2;

Code:
str_emp_dept =
((DropDownList)e.Item.FindControl(Department_dropd own2.Selected_dept_value())).SelectedValue;

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_value()
{
string dept_value = dept_dropdown.SelectedValue;
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:templatecolumn HeaderText="Department">
<itemtemplate>
<%# DataBinder.Eval(Container.DataItem, "Emp_Department") %>
</itemtemplate>
<edititemtemplate>
<uc1:department_dropdown id="Department_dropdown2" runat="server">
</uc1:department_dropdown>
</edititemtemplate>

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_dropdown Department_dropdown2;

Code:
str_emp_dept =
((DropDownList)e.Item.FindControl(Department_dropd own2.Selected_dept_value())).SelectedValue;

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_value()
{
string dept_value = dept_dropdown.SelectedValue;
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:templatecolumn HeaderText="Department">
<itemtemplate>
<%# DataBinder.Eval(Container.DataItem, "Emp_Department") %>
</itemtemplate>
<edititemtemplate>
<uc1:department_dropdown id="Department_dropdown2" runat="server">
</uc1:department_dropdown>
</edititemtemplate>

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_dropdown Department_dropdown2;

Code:
str_emp_dept =
((DropDownList)e.Item.FindControl(Department_dropd own2.Selected_dept_value())).SelectedValue;

Nov 19 '05 #4

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

Similar topics

2
1998
by: Balamurukan | last post by:
How to retrive property values from our own property window
2
4770
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...
2
2019
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...
2
2822
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...
0
1436
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...
1
1379
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...
4
5023
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...
4
1786
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...
3
3899
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...
0
7086
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
7280
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,...
1
6991
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...
0
5578
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,...
1
5014
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...
0
4672
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...
0
3167
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...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
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 ...

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.