how to get a control ID from a bind field name / bound field (column) name from a formview's control

I have a form view which is bound to a table, now from codebehind file I need to apply some formatting based on some of the field's bound control. For example, if Formview1 is bound to Employee table, and it's item template has a control with ID "Label1" which is bound to "EmployeeJoinDate" . Now, I have a different table which has a list of field name(EmployeeJoinDate is one of them), all of which should be applied some formatting based on some condition.

Now I can take two approach for that, but I am stuck at both:

 1. If I can somehow get the control ID which is bound on a particular column(eg, find the control that bounds to "EmployeeJoinDate"), I can easily apply the formatting. But I couldn't find anywhere how to do it.

2. I can iterate through all the controls in formview using FormView.Controls collection and check if it is bound to any of the field in the ConditionalFieldList, then apply the formatting. But I don't know how to find the bound field name of any control.

 Any clue? I would prefer any solution to the approach 1, as in that case I only have to iterate through only those fields, where the condition will be applied, Not all the controls inside the formview. But if it's not possible suggestion to approach 2 will also be appreciated.





1/8/2008 6:20:12 PM 72751 articles. 3 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 11

Here you go... this is pretty common... you will use FindControl...

in the Page_PreRender use this code and then do your formatting there also:

Dim Label1 As New System.Web.UI.WebControls.Label

Label1 = CType(gridbill.Rows(x).FindControl("Label1"), System.Web.UI.WebControls.Label)


Remember to "Mark As Answer" if this post has helped you! Thanks....
And I say unto you, Ask, and it shall be given you; seek, and ye shall find; knock, and it shall be opened unto you...
LK 11:9
1/8/2008 7:40:37 PM

Well you can do this  in the databound event of your formview where you have to search for your control.

Something like this:


Label lbl = (Label)FormView1.FindControl("Label1");

lbl.Id = here you can get the id you want. 


~ Remember To Mark The Post(s) That Helped You As The ANSWER ~
1/8/2008 7:56:15 PM

Maybe I was not clear enough. I know how can I get access to a webcontrol using FindControl method. But for this I need to know the Server ID of the control. But the thing is I don't know which ID the control has, I only know the bound field name(EmployeeID), using this name I want to find the controlthat is bound to this field(in this case Label1) .

1/8/2008 8:43:47 PM

Similar Artilces:

Web Custom Control
 I wrote this web custom control, and finally got all the embedded images and script files to embed, and display properly.But when I assign a name to the ID of the Control, the server changes the ID Name.So I have a control called txtMovieEmbed, and I assign the ID as txtMovieEmbed.But when the control renders, the name changes to ctl00_ContentPlaceHolder2_txtMovieEmbed txtMovieEmbed = New TextBox txtMovieEmbed.Width = 325 txtMovieEmbed.CssClass = "FormControl" txtMovieEmbed.ReadOnly = True txtMovieEmbed.Text = MovieEmbedCode txtMovieEmbed.ID = "txtMovieEmbed&qu...

pass a control name to get uniquie control Id
I have many text boxes inside an AJAX TabContainer control and I would like the background of each textbox to change colors after the user has changed the text.  i know i will need code similar to document.getElementById('<%= txtBox1.ClientID %>').style.backgroundColor='red'; because when each textbox is rendered it is given a unique id.  I have a function that looks like this <script type="text/javascript">      function mkclr(ctrl) {        var control = document.getElementById...

How to get the database column name that is bound to a FormView textbox control
I am developing a context menu for filtering and sorting.  I am trying to determine the database column that is bound to the textbox that the user was hovering over when they right-clicked. I kow that I could take a brute force approach and add an onFocus event to each control to populate a hidden field with a hard-coded column name.  I would prefer a proper dynamic approach. Any and all ideas will be appreciated.Chris Duva cjduva:I am developing a context menu for filtering and sorting.  I am trying to determine the database column that is bound to the textbox that the u...

Getting a ref (ID's or Names) for Dynamic Controls on a Page
 I have a page containing a number of dynamically created checkboxes within a gridview (1 checkbox per row). When building the gridview  I can assign an 'onclick' event handler to the control so that a client event is triggered. However I need the name/ID of the checkbox control that the user clicked on it. Is there any way to do this via Javascript/client side code? Any examples/sample code would be helpful. TIA,Patrick    onclick="alert(;"  Eric | Twitter epascarello | LinkedIn No - this will not prov...

how to get a dataitem's column name in a custom databound control
 I know how to get the value, but not its associated column name... (ie. "Name") Hi notinmyname , I hope my sample is helpful to you.   protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { DataRowView drv = e.Row.DataItem as DataRowView; for (int i = 0; i < drv.DataView.Table.Columns.Count; i++) { Response.Write(drv.DataView.Table.Columns[i].ColumnName); } } }   <fo...

Naming a document element problems (trying to getElementByID() but the id's of the control are staring with _'s, which are not valid)
This page is an almost working implementation of viewing the HTML source, you'll see the two files are very close, with the difference being that the spans in the working on faulty version are named "_ctl0_Strategy0" instead of "Strategy0". That causes the getElementByID() javascript function to fail because id's staring with _'s are not valid). Since as far as I know, I can't control the control's naming prefix (via a C# command), how do I get around this?Mark You could just append the _ctl0_ in your JavaScript.Are you making this ...

Getting the control id of a control inside gridview control
 uhmm.. a little bit confusing regarding my subject because i dont know how to say the way my problem is how can i get the id of a control (e.g. textbox) inside the gridview... and the textbox is in the templatefield... is there any way i can get its id??  hoping i could get a reply as soon as possible... Regards,MhaeyPlease remember to click “Mark as Answer” on the post that helps you.. =) What do you want's to do by getting the id of the Text box? Do you want's to find particular Textbox with certain id ? Kamran ShahidSr. Software Engineer(MCP,,MC...

Unable to access user control's user control's function\property from another user control
Hi, I used to call an user control's user control function as stated below from my user control in ASP.Net 1.1 wucCompany.wucEmployee.GetEmployeeSomething() After migrating to ASP.Net 2.0, I am unable to use any properties/functions(even the public ones) of the user control's User control's from another user control.  The way I have to do is create property\function in wucCompany which calls the wucEmployee's property\function and call the wucDepartment.GetEmployeeSomething().Since I need to do this change in too many places, I can...

how to control a RadioButtonList's Listitem's text show according database's field
Hi my page has a repeater control,in repeater has a RadioButtonList control now i want to let the RadioButtonList has four Listitem,every Listitem's text is a database's field so the listitem can show dynamic according every record how can i work out my problem thanks a lot  hello dearbound your RadioButtonList to database if i m not clear fell free 4 replySatyabrat SinghB.E.(C.Sc.)Web developer Livetek Solution Dont forget to click "Mark as Answer" on the post that helped you. yes.i bound the radiobuttonlist to a dataset but how to display the ...

how to get a control's name
 Hi  In a webform has some controls,i want to get the control's name to do other things  How can i get a control's name,such as  DropDownlist  Thanks a lot  This snippet loops through the controls in a webform and gives you the control type name. foreach (Control cntrl in form1.Controls) { Response.Write(cntrl.GetType().Name.ToString()); }   How to write the code use vb.netThanks a lot Mark Lokira's answer as the answer.  For Each cntrl As Control In form1.Controls Response.Write(cntrl.[GetType]().Name.ToString...

Label control's text doesn't appear to be set (in the page which has a user control )when trying to update the text property in the FormView's ItemUpdated event
Hi There,I have a user control which hosts a formview control, gridview control and a label control. The grid view is usedto show rows in the DB and when clicked to edit each row, a form view opens up in edit mode with that particular row info. So I have nothing in the item template.My first question it mandatory to have smth in the itemtemplate of the form view.I have controls in edititemtemplate and insertitemtemplate.When a particular row is edited, I would like to show a status msg showing that the row has been updated.For this, I use the ItemUpdated event of the formview and try ...

SqlBulkCopy: the locale id '0' of the source column '<column name> ' and the locale id '1033' of the destination column '<column name>' do not match.
Hi, I am using the sqlbulkcopy object to transfer large amount of data from one SQL server to Other. The code look like this.. SqlDataReader readerSrc = null;SqlBulkCopy bulkCopy = new SqlBulkCopy(connDest);//Prepare Destination Table.SqlCommand cmdDelete = new SqlCommand("DELETE FROM " + destTableName, connDest);//Set the sqlcommand textSqlCommand cmdGet = new SqlCommand("SELECT * FROM " + srcTableName, connSrc);//Open source connection.connSrc.Open();//Open destination connection.connDest.Open();int delete = cmdDelete.ExecuteNonQuery();//Get the data.readerSrc = cmdGet.ExecuteRead...

Ajax Control Toolkit: Control cannot be created because Visual Studio cannot find the control's type in the control assembly.
Hi All, Good Day.  I am using ASP.Net 2.0 Framework, i have downloaded Ajax 3.0 and added reference into the project. But i am not able to add controls to the page. When i tried to add control into the page getting following error message "Control cannot be created because Visual Studio cannot find the control's type in the control assembly". I checked some forums on the web, added references in Web.Config. Still not able to proceed further. Please revert asap.  Thanks. AJAX 3.0 not work in 2.0 Framework its work in 3.5 Framework try to download another ...

How to control field names?
Is there a way to control the field names that DataArchitect should generate for a PDM from a CDM? I've got a CDM with a table Part and another table User. The table Part has got some relationships with the User table (created by, changed by, ...). When I generate the PDM DataArchitect generates (based on the .DEF file I suppose) some fields for the relationships but they get strange names (USERID, FT_USERID, FT_2_USERID and so on). I would like to control the way the field names are generated so that they are called something like PARTCREATEDBY, PARTCHANGEDBY,... I changed the ...

Web resources about - how to get a control ID from a bind field name / bound field (column) name from a formview's control -

Resources last updated: 12/14/2015 6:40:55 PM