Acquire control in TemplateField by Id.

Z

zlf

Hello,
I have a GridView with TemplateField. I want to get the <asp:TextBox
ID="TextBox1" runat="server"></asp:TextBox> in 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
 
T

Thomas Hansen

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/AllControlsSamples/CalendarWebApplicationWithDateTimePicker.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
 
Z

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.
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top