|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Referencing controls in a template programmaticallyHi
Anyone know the code required to reference, i.e set and modify the controls inside a template, for example I have a form control that contains a number of textboxes in a template. I want to avoid setting the reference on the html page such as Text='<%# Bind("FORNumber") %>' Instead I want to bind them programmatically, I can't find out where or how to do this, any help appreciated, Cheers Karl Edwards Try stuff like this...
controlName.Controls[0].Controls[0].Controls[1] combined with controlName.FindControl("controlName2") to make something that looks like this gvMyData.Controls[0].Controls.[1].Controls[0].FindControl("ddlMyNames") Thats how you can grab the control... Then you can do something like this ((DropDownList)(gvMyData.Controls[0].Controls.[1].Controls[0].FindControl("ddlMyNames")).DataSource = GetData( ); ((DropDownList)(gvMyData.Controls[0].Controls.[1].Controls[0].FindControl("ddlMyNames")).DataBind( ); Thanks I'll give it a try but it does seem so messy
any idea why I just can't say formName.controlName = "whatever" <agape***@gmail.com> wrote in message Show quoteHide quote news:1134269352.451216.209530@f14g2000cwb.googlegroups.com... > Try stuff like this... > > controlName.Controls[0].Controls[0].Controls[1] > > combined with > > controlName.FindControl("controlName2") > > to make something that looks like this > > gvMyData.Controls[0].Controls.[1].Controls[0].FindControl("ddlMyNames") > > Thats how you can grab the control... > > Then you can do something like this > > ((DropDownList)(gvMyData.Controls[0].Controls.[1].Controls[0].FindControl("ddlMyNames")).DataSource > = GetData( ); > > ((DropDownList)(gvMyData.Controls[0].Controls.[1].Controls[0].FindControl("ddlMyNames")).DataBind( > ); > Just to make it a bit clearer, the following is the way asp.net 2 creates
the code placing the controls in the template and binding them on the aspx page. I don't want any code on the aspx page. FORNumber: <asp:Label ID="txtFORNumber" runat="server" Text='<%# Bind("FORNumber") %>'></asp:Label><br /> I want to do this programmatically so the <%# Bind("FORNumber") %> is done in the code behind. The controls are inside a form control on the ItemTemplate Cheers <k***@sunesis.com.au> wrote in message Show quoteHide quote news:eqUgXgq$FHA.916@TK2MSFTNGP10.phx.gbl... > Thanks I'll give it a try but it does seem so messy > any idea why I just can't say formName.controlName = "whatever" > > > <agape***@gmail.com> wrote in message > news:1134269352.451216.209530@f14g2000cwb.googlegroups.com... >> Try stuff like this... >> >> controlName.Controls[0].Controls[0].Controls[1] >> >> combined with >> >> controlName.FindControl("controlName2") >> >> to make something that looks like this >> >> gvMyData.Controls[0].Controls.[1].Controls[0].FindControl("ddlMyNames") >> >> Thats how you can grab the control... >> >> Then you can do something like this >> >> ((DropDownList)(gvMyData.Controls[0].Controls.[1].Controls[0].FindControl("ddlMyNames")).DataSource >> = GetData( ); >> >> ((DropDownList)(gvMyData.Controls[0].Controls.[1].Controls[0].FindControl("ddlMyNames")).DataBind( >> ); >> > >
2.0 menu control and color
Understanding query strings VS2005 Designer does NOT display asp:panels!! Why? contenteditable Coding issue Control.Controls bug? Control's child controls missing at the run time. View State problem when multiple user work on the same page onload called only once Custom Buttons preserve password field over steps in wizard |
|||||||||||||||||||||||