473,837 Members | 1,646 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Raising an event of a control inside Templatefield within GridView

Nam
I have a DropDownList control in a TemplateField inside my GridView
How do I access this control’s SelectedIndexCh anged event in codeBehind
page? I don’t see the ID “DropDownList 1” of this control in the list of
objects in odeBehind page.

GridView1 and DropDownList1 are bound to TWO DIFFERENT tables (DataSources).
The last column of each row in the GridView is shown as a DropDownList. I
want to use the SelectedIndexCh anged event of DropDownList1 to capture the
valued selected in the dropdown by the user.

Following is the sample code from aspx file:

Thanks,
Nam

<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateCol umns="False" DataKeyNames="f ilmTypeID"
DataSourceID="S qlDataSource1" CellPadding="4"
ForeColor="#333 333" GridLines="None ">
<Columns>
<asp:CommandFie ld ShowSelectButto n="True" />
<asp:BoundFie ld DataField="film TypeID"
HeaderText="fil mTypeID" InsertVisible=" False"
ReadOnly="True" SortExpression= "filmTypeID " />
<asp:BoundFie ld DataField="film Type" HeaderText="fil mType"
SortExpression= "filmType" />
<asp:TemplateFi eld>
<ItemTemplate >
<asp:DropDownLi st ID="DropDownLis t1" runat="server"
DataSourceID="S qlDataSource2"
DataTextField=" answer" DataValueField= "answerID"
Enabled="false"
>
</asp:DropDownLis t>
<asp:SqlDataSou rce ID="SqlDataSour ce2"
runat="server" ConnectionStrin g="<%$ ConnectionStrin gs:Northwind %>"
SelectCommand=" SELECT CustomerID, CompanyName
FROM Customers">
<SelectParamete rs>
<asp:Paramete r DefaultValue="7 "
Name="questionI D" />
</SelectParameter s>
</asp:SqlDataSour ce>
</ItemTemplate>
</asp:TemplateFie ld>

</Columns>
<FooterStyle BackColor="#5D7 B9D" Font-Bold="True"
ForeColor="Whit e" />
<RowStyle BackColor="#F7F 6F3" ForeColor="#333 333" />
<EditRowStyle BackColor="#999 999" />
<SelectedRowSty le BackColor="#E2D ED6" Font-Bold="True"
ForeColor="#333 333" />
<PagerStyle BackColor="#284 775" ForeColor="Whit e"
HorizontalAlign ="Center" />
<HeaderStyle BackColor="#5D7 B9D" Font-Bold="True"
ForeColor="Whit e" />
<AlternatingRow Style BackColor="Whit e" ForeColor="#284 775" />
</asp:GridView>
<asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:Northwind %>"
SelectCommand=" SELECT LastName FROM
Employees"></asp:SqlDataSour ce>
<br />
<asp:Label ID="Label1" runat="server" Text="test"
Width="160px"></asp:Label></div>
</form>
</body>

Jul 4 '06 #1
1 10449
Nam
I got the answer to my own question from the following article:

http://webthingsconsidered.blogspot....idview-or.html

Thanks,
Nam

"Nam" wrote:
I have a DropDownList control in a TemplateField inside my GridView
How do I access this control’s SelectedIndexCh anged event in codeBehind
page? I don’t see the ID “DropDownList 1” of this control in the list of
objects in odeBehind page.

GridView1 and DropDownList1 are bound to TWO DIFFERENT tables (DataSources).
The last column of each row in the GridView is shown as a DropDownList. I
want to use the SelectedIndexCh anged event of DropDownList1 to capture the
valued selected in the dropdown by the user.

Following is the sample code from aspx file:

Thanks,
Nam

<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateCol umns="False" DataKeyNames="f ilmTypeID"
DataSourceID="S qlDataSource1" CellPadding="4"
ForeColor="#333 333" GridLines="None ">
<Columns>
<asp:CommandFie ld ShowSelectButto n="True" />
<asp:BoundFie ld DataField="film TypeID"
HeaderText="fil mTypeID" InsertVisible=" False"
ReadOnly="True" SortExpression= "filmTypeID " />
<asp:BoundFie ld DataField="film Type" HeaderText="fil mType"
SortExpression= "filmType" />
<asp:TemplateFi eld>
<ItemTemplate >
<asp:DropDownLi st ID="DropDownLis t1" runat="server"
DataSourceID="S qlDataSource2"
DataTextField=" answer" DataValueField= "answerID"
Enabled="false"
>
</asp:DropDownLis t>
<asp:SqlDataSou rce ID="SqlDataSour ce2"
runat="server" ConnectionStrin g="<%$ ConnectionStrin gs:Northwind %>"
SelectCommand=" SELECT CustomerID, CompanyName
FROM Customers">
<SelectParamete rs>
<asp:Paramete r DefaultValue="7 "
Name="questionI D" />
</SelectParameter s>
</asp:SqlDataSour ce>
</ItemTemplate>
</asp:TemplateFie ld>

</Columns>
<FooterStyle BackColor="#5D7 B9D" Font-Bold="True"
ForeColor="Whit e" />
<RowStyle BackColor="#F7F 6F3" ForeColor="#333 333" />
<EditRowStyle BackColor="#999 999" />
<SelectedRowSty le BackColor="#E2D ED6" Font-Bold="True"
ForeColor="#333 333" />
<PagerStyle BackColor="#284 775" ForeColor="Whit e"
HorizontalAlign ="Center" />
<HeaderStyle BackColor="#5D7 B9D" Font-Bold="True"
ForeColor="Whit e" />
<AlternatingRow Style BackColor="Whit e" ForeColor="#284 775" />
</asp:GridView>
<asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:Northwind %>"
SelectCommand=" SELECT LastName FROM
Employees"></asp:SqlDataSour ce>
<br />
<asp:Label ID="Label1" runat="server" Text="test"
Width="160px"></asp:Label></div>
</form>
</body>
Jul 8 '06 #2

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

Similar topics

6
2887
by: Dan | last post by:
I've created a pocketpc app which has a startup form containing a listview. The form creates an object which in turn creates a System.Threading.Timer. It keeps track of the Timer state using a TimerState object similar to the example in the System.Threading.Timer documentation. The method which handles the timer events, among other things, periodically calls a method in this TimerState object which raises an event to the startup form,...
4
34535
by: huzz | last post by:
I am trying to access a DropDownList control inside a repeater using ItemCommand as shown below but for some reason i can't access the DropDownList. When i step through the debug i get <undefine value> for the DropDownList What am i doing wrong? <asp:Repeater ID="Repeater1" Runat="server" OnItemDataBound="create_ddl" OnItemCommand="Repeater1_ItemCommand"> <HeaderTemplate>
4
4799
by: vatech1993 | last post by:
I'm stumped on this problem. I've created a user control that dynamically creates 5 linkbuttons in the CreateChildControls method. Each of these child controls is linked to a commandeventhandler, has command name and argument attached and is assigned a unique id. If I use this control on a web form everything works fine, the event fires as planned. However if I contain the control inside another user control, the event on the linkbutton...
1
6297
by: waihung.wee | last post by:
Hi I got the following error in my xxx.cs file (code behind file) According to the error message, I should add a form tag in the file. But form tag should not appear in a code behind file Can anyone please help. Thanks
2
2326
by: ccbalapatel | last post by:
Hi, We have recently converted our code to ASP.NET 2.0. We have an user control that is embedded inside the page. The user control has a link button and the event handler for the link button is written inside the user control. When the link button is clicked, the page is posted back and the page_load method of the user control also executes fine. But, the event handler for the link button is not called. The same code works fine on ASP.NET...
14
91379
by: Mike | last post by:
I have a gridview that has a button in the last cell of each row. I want to get the text from cell 1 for that row the button was clicked on. So if my gridview looks like this: N-12 BMW N-35 Mercedes if my user clicks row 2, I want to see Mercedes, How can I do that? I have a buttonClick event for my select button, I'm trying to pull the values using the DataKeyName, but I keep getting 'object reference...
1
2186
by: ajrock2000 | last post by:
I am using a DetailsView to display some data. I am basically getting a firstname, and lastname fields from a database (the database cannot be changed, nor the queries), and I must concatenate the , . I want to incorporate this into a detailsview like so... <asp:TemplateField HeaderText="Name:"> <ItemTemplate> <%#Eval("firstname")%>, <%#Eval("lastname")%> </ItemTemplate> </asp:TemplateField> ...
1
2035
by: =?Utf-8?B?U2F2dm91bGlkaXMgSW9yZGFuaXM=?= | last post by:
How can I use Findcontrol inside a master gridview's RowDatabound event to search for another gridview (detail) control that is inside an ASP Panel, in a template column of the master gridview?
3
1769
by: remohy1 | last post by:
i cant control properties of the control inside the gridview lets give an example when i put a button in a itemplate in gridview and write code protected void Button4_Click(object sender, EventArgs e) { (sender as Button).Visible = false; }
0
9683
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,...
0
10883
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10633
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,...
1
7814
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
7007
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
5674
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
5852
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4050
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3126
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.