473,382 Members | 1,202 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,382 software developers and data experts.

reference to controls in template item

Hello,

The situation is like follow:

I've got GridView1 correlated with DetailsView1 (it's normal scenario). In
DetailView1 I've got CRUD operations enabled. For create and edit opeartion
I've 2 ItemTemplates. One of them is DropDownList2 (with AutoPostBack
enabled) and 2-nd one is GridView2 (dependent on DropDownList2). All I want
is to have GridView2 updated when I change option in DropDownList2.
I thought that I can do that in code behind (Selected event of
DropDownList2) by changing SqlDataSource which is bound to GridView2. But I
don't know how to refer to these "embedded" controls.

Best Regards

D.T.
Apr 3 '07 #1
4 1964
Czesc Darek,

What about FindControl() method?:

DropDownList dropDownList = (DropDownList)
DetailView1.FindControl("DropDownList1")
string selectedValue = dropDownListSelectedValue;

or use asp:ControlParameter in sqldatasource control. The only problem with
the second approach (in this case) is you have to provide container(s)
control id as well:

<asp:SqlDataSource runat="server" ID="SqlDataSource1">
<SelectParameters>
<asp:ControlParameter ControlID="DetailsView1$DropDwonList1"
PropertyName="SelectedValue"/>
</SelectParameters>
</asp:SqlDataSource>

Hope this helps
--
Milosz
"Dariusz Tomon" wrote:
Hello,

The situation is like follow:

I've got GridView1 correlated with DetailsView1 (it's normal scenario). In
DetailView1 I've got CRUD operations enabled. For create and edit opeartion
I've 2 ItemTemplates. One of them is DropDownList2 (with AutoPostBack
enabled) and 2-nd one is GridView2 (dependent on DropDownList2). All I want
is to have GridView2 updated when I change option in DropDownList2.
I thought that I can do that in code behind (Selected event of
DropDownList2) by changing SqlDataSource which is bound to GridView2. But I
don't know how to refer to these "embedded" controls.

Best Regards

D.T.
Apr 3 '07 #2
Thank you for your advice.
Actually I solved the problem very alike :)

protected void ddl_DeviceType_SelectedIndexChanged(object sender, EventArgs
e)

{

string a = DetailsView1.FindControl("ddl_DeviceType").ID.ToSt ring();

DropDownList ddl = new DropDownList();

ddl = (DropDownList)DetailsView1.FindControl("ddl_Device Type");

a = ddl.SelectedItem.ToString();

}

Best Regards

D.T.
"Milosz Skalecki [MCAD]" <mi*****@DONTLIKESPAMwp.plwrote in message
news:EE**********************************@microsof t.com...
Czesc Darek,

What about FindControl() method?:

DropDownList dropDownList = (DropDownList)
DetailView1.FindControl("DropDownList1")
string selectedValue = dropDownListSelectedValue;

or use asp:ControlParameter in sqldatasource control. The only problem
with
the second approach (in this case) is you have to provide container(s)
control id as well:

<asp:SqlDataSource runat="server" ID="SqlDataSource1">
<SelectParameters>
<asp:ControlParameter ControlID="DetailsView1$DropDwonList1"
PropertyName="SelectedValue"/>
</SelectParameters>
</asp:SqlDataSource>

Hope this helps
--
Milosz
"Dariusz Tomon" wrote:
>Hello,

The situation is like follow:

I've got GridView1 correlated with DetailsView1 (it's normal scenario).
In
DetailView1 I've got CRUD operations enabled. For create and edit
opeartion
I've 2 ItemTemplates. One of them is DropDownList2 (with AutoPostBack
enabled) and 2-nd one is GridView2 (dependent on DropDownList2). All I
want
is to have GridView2 updated when I change option in DropDownList2.
I thought that I can do that in code behind (Selected event of
DropDownList2) by changing SqlDataSource which is bound to GridView2. But
I
don't know how to refer to these "embedded" controls.

Best Regards

D.T.

Apr 3 '07 #3
Czesc Milosz,

Zauwazylem adres wp.pl wiec mozna po polsku chociaz lista jest eng (ale jak
sie wczytaja to pewnie zatrybia :)
Ok w kazdym razie taka sprawa:

Mam nested gridview w DetailsView ktora pozwala mi wybrac konkretny rekord.
Ale jak robie sortowanie po kolumnie to wywal mi taki blad:

**********************************************

Databinding methods such as Eval(), XPath(), and Bind() can only be used in
the context of a databound control.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Databinding methods
such as Eval(), XPath(), and Bind() can only be used in the context of a
databound control.

Source Error:
[No relevant source lines]
Source File: c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temp orary ASP.NET
Files\zasobyit2\2486c2d0\3d86e288\App_Web_wslajwmy .0.cs Line: 0

Stack Trace:
[InvalidOperationException: Databinding methods such as Eval(), XPath(), and
Bind() can only be used in the context of a databound control.]
System.Web.UI.Page.GetDataItem() +1996914
ASP.infohardware_aspx.__DataBinding__control127(Ob ject sender, EventArgs
e) in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temp orary ASP.NET
Files\zasobyit2\2486c2d0\3d86e288\App_Web_wslajwmy .0.cs:0
System.Web.UI.Control.OnDataBinding(EventArgs e) +99
System.Web.UI.WebControls.DataBoundControl.OnDataS ourceViewSelectCallback(IEnumerable
data) +51
System.Web.UI.DataSourceView.Select(DataSourceSele ctArguments arguments,
DataSourceViewSelectCallback callback) +29
System.Web.UI.WebControls.DataBoundControl.Perform Select() +149
System.Web.UI.WebControls.BaseDataBoundControl.Dat aBind() +70
System.Web.UI.WebControls.GridView.DataBind() +4
System.Web.UI.WebControls.BaseDataBoundControl.Ens ureDataBound() +82
System.Web.UI.WebControls.GridView.OnPreRender(Eve ntArgs e) +24
System.Web.UI.Control.PreRenderRecursiveInternal() +77
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1360

--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET
Version:2.0.50727.42
******************************************

Dodam ze reprezentacja tego pola w templateitem ale w widoku "normalnym" bez
edycji jest labelka.

Masz moze jakis pomysl jak to obejsc? Idealnie chcialbym uzyskac
wspolzaleznosc pomiedzy 2 osadzonymi gridview tak aby wybranie rekordu z
jedego powodowalo zawezenie wynikow 2-giego. Oczywiscie te 2 kontrolgi sa
embedded.

Pozdrawiam

Darek
"Milosz Skalecki [MCAD]" <mi*****@DONTLIKESPAMwp.plwrote in message
news:EE**********************************@microsof t.com...
Czesc Darek,

What about FindControl() method?:

DropDownList dropDownList = (DropDownList)
DetailView1.FindControl("DropDownList1")
string selectedValue = dropDownListSelectedValue;

or use asp:ControlParameter in sqldatasource control. The only problem
with
the second approach (in this case) is you have to provide container(s)
control id as well:

<asp:SqlDataSource runat="server" ID="SqlDataSource1">
<SelectParameters>
<asp:ControlParameter ControlID="DetailsView1$DropDwonList1"
PropertyName="SelectedValue"/>
</SelectParameters>
</asp:SqlDataSource>

Hope this helps
--
Milosz
"Dariusz Tomon" wrote:
>Hello,

The situation is like follow:

I've got GridView1 correlated with DetailsView1 (it's normal scenario).
In
DetailView1 I've got CRUD operations enabled. For create and edit
opeartion
I've 2 ItemTemplates. One of them is DropDownList2 (with AutoPostBack
enabled) and 2-nd one is GridView2 (dependent on DropDownList2). All I
want
is to have GridView2 updated when I change option in DropDownList2.
I thought that I can do that in code behind (Selected event of
DropDownList2) by changing SqlDataSource which is bound to GridView2. But
I
don't know how to refer to these "embedded" controls.

Best Regards

D.T.

Apr 3 '07 #4
Czolem Darek,

Musze przyznac ze troche zamieszales pomimo ze dziala :-)
1. nie musisz inicjalizowac zmiennej poprzez tworzenie nowej instancji
dropdownlist skoro ona juz istnieje i zostanie zwrocona z metody FindControl()
2. wiekszosc zdazen przekazuje referencje do obiektu ktorego zdazenie
dotyczy z paramnetrze sender (w tym przypadku bedzie to referencja do
3. podobnie jak w pkt.1, nie musisz inicjalizowac stringa ID controlki

Powinno byc mniej wiecej tak:

protected void ddl_DeviceType_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList ddl = (DropDownList) sender;
string value = ddl.SelectedValue;
}

albo

protected void ddl_DeviceType_SelectedIndexChanged(object sender, EventArgs e)
{
string a;
DropDownList ddl = (DropDownList)
DetailsView1.FindControl("ddl_DeviceType");
a = ddl.SelectedValue.ToString();
}

Widze ze cos Ci jeszcze tam nie dziala (nastepny post) wiec moze bedzie
szybciej jak podeslesz mi kod na maila.

Uszanowanie
--
Milosz
"Dariusz Tomon" wrote:
Thank you for your advice.
Actually I solved the problem very alike :)

protected void ddl_DeviceType_SelectedIndexChanged(object sender, EventArgs
e)

{

string a = DetailsView1.FindControl("ddl_DeviceType").ID.ToSt ring();

DropDownList ddl = new DropDownList();

ddl = (DropDownList)DetailsView1.FindControl("ddl_Device Type");

a = ddl.SelectedItem.ToString();

}

Best Regards

D.T.
"Milosz Skalecki [MCAD]" <mi*****@DONTLIKESPAMwp.plwrote in message
news:EE**********************************@microsof t.com...
Czesc Darek,

What about FindControl() method?:

DropDownList dropDownList = (DropDownList)
DetailView1.FindControl("DropDownList1")
string selectedValue = dropDownListSelectedValue;

or use asp:ControlParameter in sqldatasource control. The only problem
with
the second approach (in this case) is you have to provide container(s)
control id as well:

<asp:SqlDataSource runat="server" ID="SqlDataSource1">
<SelectParameters>
<asp:ControlParameter ControlID="DetailsView1$DropDwonList1"
PropertyName="SelectedValue"/>
</SelectParameters>
</asp:SqlDataSource>

Hope this helps
--
Milosz
"Dariusz Tomon" wrote:
Hello,

The situation is like follow:

I've got GridView1 correlated with DetailsView1 (it's normal scenario).
In
DetailView1 I've got CRUD operations enabled. For create and edit
opeartion
I've 2 ItemTemplates. One of them is DropDownList2 (with AutoPostBack
enabled) and 2-nd one is GridView2 (dependent on DropDownList2). All I
want
is to have GridView2 updated when I change option in DropDownList2.
I thought that I can do that in code behind (Selected event of
DropDownList2) by changing SqlDataSource which is bound to GridView2. But
I
don't know how to refer to these "embedded" controls.

Best Regards

D.T.


Apr 6 '07 #5

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

Similar topics

1
by: bill yeager | last post by:
I did some more debugging and found the following: 1) I placed the following code in the button event just to see if I could cycle thru the datagrid control collection: <code> Dim strhello As...
3
by: Patrick.O.Ige | last post by:
I'm loading an Array below but getting the error "Object reference not set to an instance saying 'ItemNumber = CType(Args.Item.FindControl("ItemNumber"), TextBox).Text' is the error line. I DON'T...
1
by: Don | last post by:
I created a Web User Control in my project and need to use it in a datagrid. The data in this control needs to be updated and the control has several properties that need to be databound. Using...
5
by: Amelyan | last post by:
How can I get state of dynamically created controls (RadioButton, CheckBox, TextBox.Text) on post back when I click submit button? The only way I know is by traversing Response.Form enumberator;...
3
by: Raed Sawalha | last post by:
I have datagrid , i edited the template column by adding checkbox on in templateheader and one in templateitem the problem i have i can not get access to the checkbox at runtime , i did this to...
4
by: WB | last post by:
Hi, How can I generate web controls such as textboxes and drop-menus on the fly? My web application allows users to fill out PDF forms online. There are many PDF forms, and my application...
1
by: Abhishek | last post by:
I am creating a Datagrid at runtime and I have to create all the columns of grid at runtime... I am facing problem in the item template column. Here I want to place more than one control... For...
15
by: Arpan | last post by:
Consider the following code which retrieves data from a SQL Server 2005 DB table & displays it in a DataGrid: <script runat="server"> Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)...
2
by: Jerod Hatley | last post by:
when I try to add two controls to an item template, I cannot figure out how to keep them on a single line. the functionality is just fine but how do I get the controls to render on a single line?...
2
by: AC [MVP MOSS] | last post by:
I have a repeater with a header, footer, and item template. The item template is the only one with server controls (hyperlinks, labels, and a nested repeater). Within the top repeater, I'm handling...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.