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

Acquire control in TemplateField by Id.

zlf
Hello,
I have a GridView with TemplateField. I want to get the <asp:TextBox
ID="TextBox1" runat="server"></asp:TextBoxin TemplateField in programmatic
way. e.g: GridView1.TextBox1 or GridView1.FindControl("TextBox1"), but
neither of them works. Please help me.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="Employeeid"
DataSourceID="ObjectDataSource1">
<Columns>
<asp:BoundField DataField="Country" HeaderText="Country"
SortExpression="Country" />
<asp:TemplateField HeaderText="link">
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Thanks

zlf
Aug 24 '07 #1
3 1748
On Aug 24, 3:16 pm, "zlf" <zl...@hotmail.comwrote:
Hello,
I have a GridView with TemplateField. I want to get the <asp:TextBox
I have a suspicion that what you'd want to do would be more
interesting than
HOW to do it...

Why do you need the Control?
Is it to extract some kind of ID?

Check out this sample;
http://ajaxwidgets.com/AllControlsSa...imePicker.aspx
(Click the "Show Code for this sample")

Sure it's epcific for Gaia Ajax Widgets, but still it's the exact same
syntax with conventional APS.NET...
..t

Aug 24 '07 #2
zlf
Actually, the control I want to get is not a TextBox, it is custom control.
And I need to assign some special property of it to make it display
specified data.

"Thomas Hansen" <po*******@gmail.com>
??????:11**********************@q4g2000prc.googleg roups.com...
On Aug 24, 3:16 pm, "zlf" <zl...@hotmail.comwrote:
>Hello,
I have a GridView with TemplateField. I want to get the <asp:TextBox

I have a suspicion that what you'd want to do would be more
interesting than
HOW to do it...

Why do you need the Control?
Is it to extract some kind of ID?

Check out this sample;
http://ajaxwidgets.com/AllControlsSa...imePicker.aspx
(Click the "Show Code for this sample")

Sure it's epcific for Gaia Ajax Widgets, but still it's the exact same
syntax with conventional APS.NET...
.t

Aug 24 '07 #3
This is probably what you were looking for.

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
TextBox c = (TextBox) e.Row.FindControl("TextBox1");
if (c!=null)
{
// set properties
}
else
{
// did not find or was binding Footer/Headers etc.
}
Int32 d = 0;
}

YUou also can bind properties declaratively using Eval or Container.DataItem

"zlf" wrote:
Hello,
I have a GridView with TemplateField. I want to get the <asp:TextBox
ID="TextBox1" runat="server"></asp:TextBoxin TemplateField in programmatic
way. e.g: GridView1.TextBox1 or GridView1.FindControl("TextBox1"), but
neither of them works. Please help me.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="Employeeid"
DataSourceID="ObjectDataSource1">
<Columns>
<asp:BoundField DataField="Country" HeaderText="Country"
SortExpression="Country" />
<asp:TemplateField HeaderText="link">
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Thanks

zlf
Aug 24 '07 #4

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

Similar topics

1
by: Zule | last post by:
Hi, I am creating a Composite Control within which I have a GridView. In this GridView, I have three TemplateFields, the last one being a template with a LinkButton which is meant to be clicked...
5
by: Siva | last post by:
Hello I have a dropdownlist inside the gridview as a template column defined as follows: <asp:TemplateField HeaderText="Choose Location"> <ItemTemplate> <asp:DropDownList ID="ddlChooseLoc"...
1
by: Nam | last post by:
I have a DropDownList control in a TemplateField inside my GridView How do I access this control’s SelectedIndexChanged event in codeBehind page? I don’t see the ID “DropDownList1” of...
2
by: Ben | last post by:
Hi, In the code-behind, i can refer to the dropdownlist defined in the aspx file with this (e.g.) dropdownlist1.sekectedvalue = ... but why can i not refer to the label defined in the...
3
parshupooja
by: parshupooja | last post by:
Hey All, I am trying to used Masked Edit controls of Ajax in gridview. I have 14 rows in gridview,but masked edit control only works for first row. Any Idea. Plz Help <asp:GridView...
2
by: Danielle | last post by:
Hello all - Thank you in advance for any help you are able to provide. I am populating a gridview from a stored procuedure. The returned data is a name, phone number, email and guid of a...
1
by: ranger979 | last post by:
I am using the emptydatatemplate for a gridview control. I have a detailsview control within the emptydatatemplate. In the detailsview I have another templatefield that contains an imagebutton...
1
by: ranger979 | last post by:
I am using the emptydatatemplate for a gridview control. I have a detailsview control within the emptydatatemplate. In the detailsview I have a templatefield that contains an imagebutton control...
3
by: kimbred | last post by:
Can someone help? I have the code below in which I'm attempting to show or hide the edit control in a gridview based on the value of a column in that view. It doesn't seem to find the control. ...
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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 projectplanning, coding, testing,...

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.