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
0
cjduva
9/28/2007 4:32:02 AM
asp.net.web-forms 93655 articles. 5 followers. Follow

3 Replies
602 Views

Similar Articles

[PageSpeed] 2

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

Hi cjduva,

Base on my experience, you use the following code snippet and JavaScript to solve your problem:

C# Code:

      DataTable dt = new DataTable();//you can write the logic code to get a datatable instance here, as a demo,I do not write it.
        ArrayList al = new ArrayList();
        foreach (DataColumn dc in dt.Columns)
        {
            al.Add(dc.ColumnName);
        }

JavaScript:


            function getCounumByArrayIndex( txtBoxInstanceID, Index ){
                document.getElementById( txtBoxInstanceID ).value = arraylist[Index];
        }

HTML : 

   <input type="text" id="demo" onmousedown="getCounumByArrayIndex('demo','0')" />


I do not write a whole demo, I just give a solution for your reference only, and I am sure it can be solving your problem.

 

Please correct me if I have misunderstood your mean, please LET ME KNOW, Thanks, 

Hope it helps,

Hong Gang

 


Hong-Gang Chen
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Hong
10/3/2007 7:28:45 AM

If I understand correctly:

  1. The C# code populates an array with the column names of my database table.
  2. The Javascript function is supplied with the control ID and an array subscript from the onMouseDown event (0 in the example) of the control and returns a column name  from the array as the value of the text box.

Effectively, it seems that I would be hard-coding the control parameter to the column names array (0,Column1 then 1,Column2 etc).

What I have chosen to do is simply set the name of the control to be the same as the database column that is bound to it.  I get the control when the onMouse event fires and strip the name from the placeholder.

Thank you for your help.


Chris Duva
0
cjduva
10/3/2007 11:29:43 PM

cjduva:

If I understand correctly:

  1. The C# code populates an array with the column names of my database table.
  2. The Javascript function is supplied with the control ID and an array subscript from the onMouseDown event (0 in the example) of the control and returns a column name  from the array as the value of the text box.

Effectively, it seems that I would be hard-coding the control parameter to the column names array (0,Column1 then 1,Column2 etc).

What I have chosen to do is simply set the name of the control to be the same as the database column that is bound to it.  I get the control when the onMouse event fires and strip the name from the placeholder.

 

Hi  cjduva,

Yes, you understand very well. 

cjduva:
Effectively, it seems that I would be hard-coding the control parameter to the column names array (0,Column1 then 1,Column2 etc).

Yes, if you use my solution. Embarrassed

cjduva:
What I have chosen to do is simply set the name of the control to be the same as the database column that is bound to it.  I get the control when the onMouse event fires and strip the name from the placeholder.

I can not catch your point well, could you give me more details?

Waiting for you feedback,

Hong Gang 



Hong-Gang Chen
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Hong
10/4/2007 7:46:59 AM
Reply:

Similar Artilces:

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

C#.NET WEB APPLICATION
hei guys, i need help on my application, i'm using C#.NET as front-ed and SQL as back-end, aside from a datagrid, i want to display my data using textboxes and not a datagrid, i can do it using Visual Basic 6 but since i'm a newbee at C#.NET i don't know how to do it, specially the codes, can anyone help me with it? thank you in advance! If you are doing windows development, i would suggest using 'DataForm wizard' (Use Solution Explorer-->Rightclick project-->Add new Item-->New DataForm). It will guide you through steps. If you are doing web apps. Use quickstart to learn them. h...

Showing my own column names instead of database column names in datagridview-windows app. C#.net
HiI already bind a DataGridView to a databse. My DataGridView is showing column names as it is in the table. I want to show user-friendly column names in the grid instead of column names in the database table. Please help me in this reagard. Thanx in advance Your statement indicates to me that your columns are dynamically added to the grid, that's why it's showing the database column names. You can show user-friendly column names by changing your query like so: SELECT fName as 'First Name' FROM Users.DarmarkMark as Answer, if this reply answers your post. Go to "E...

How do I get data form a Formview to other control (like Label or TextBox)
Hello, I’m using Visual Web Developer 2005 Express Edition to create a simple web page. I have used a Formview to get the data from a Database. It is work fine. Now I want to read the data in Formview and assign to another control in same page. (like TextBox). Or data from another control in same page and assign to the  FormView.? How do I do that? something like this works to retrieve the info from the formview.... assuming your FormView ItemTemplate has a label called "FirstName" FormView fv = FormView1;Label myfvLabel = ((Label)fv.FindControl("FirstName"));TextB...

How to get a changed web form control name to use in javascript?
When you use a user control, all web form controls names get changed by .NET some like ctl0_ctl5_txtFirstName where txtFirstName is the actual name I gave. in Javascript, to refer to this control I can do like document.getElementById('ctl0_ctl5_txtFirstName') but the thing is from time to time, the prefix, in this case ctl0_ctl5_, gets changed again. So the javascript does not work anymore. Is there any way of handling this situation? Is there any server method to get the prefix? If then I can send the prefix to client side and prefix it with actuall control name like var ...

Is there any tool in .Net to collect database columns'name,datatype and create get/set function in class automatically?
Hi there, I have some big tables with many columns, I want to write classes to include all the columns, it's too time-consuming to write codes by hand. I wonder if there is a tool or any simple ways in .Net to collect database columns'name,datatype and create get/set function in class automatically? Any ideas are appreciated. CodeSmith has a strongly typed collections (which is what it sounds like you want) generator. It's free. Find out more here: http://www.ericjsmith.net/codesmith/ No, I don't get any money or anything for sending you there. I just use it ever...

validate Textbox in Web User Control from web form?
ASP.NET 2.0 I have a web user control that contains a textbox.  I need to add some validation (like requiredfieldvalidator, comparevalidator, etc). I would normally add the validator to my web user control by placing the validator next to my textbox.  However, I need the validation message somewhere else on my web form, not near the user control. So how would I associate a validation control on my web form with the text box inside my web user control?  Can this be done; any alternatives out there? Thanks!   The error message should occur wherever you place the vali...

Embedded web control inside a FormView control
FormView1's InsertItemTemplate contains DropDownList1 which has autoPostBack=True In the code-behind I can't figure out how to name the DropDownList The name of DropDownList1 in the Solution Explorer is: FormView1.InsertItemTemplate.InsertItemTemplate.DropDownList1 But using this name in the code behind gives an error: InserItemTemplate is not a member of 'System.Web.UI.ITemplate No combination of shorter names wil be accepted Any suggestions, please? did you find an answer to this? No, Unfortunately, I never did foind an answer to this Hope you are in better luck...

superreview granted: [Bug 288906] Return null for MSAA name when no name explicitly set for HTML form control : [Attachment 179538] If no name explictly set for form control, use SetIsVoid(null)
neil@parkwaycc.co.uk <neil.parkwaycc.co.uk@myrealbox.com> has granted Aaron Leventhal <aaronleventhal@moonset.net>'s request for superreview: Bug 288906: Return null for MSAA name when no name explicitly set for HTML form control https://bugzilla.mozilla.org/show_bug.cgi?id=288906 Attachment 179538: If no name explictly set for form control, use SetIsVoid(null) https://bugzilla.mozilla.org/attachment.cgi?id=179538&action=edit ...

superreview requested: [Bug 288906] Return null for MSAA name when no name explicitly set for HTML form control : [Attachment 179538] If no name explictly set for form control, use SetIsVoid(null)
Aaron Leventhal <aaronleventhal@moonset.net> has asked neil@parkwaycc.co.uk <neil.parkwaycc.co.uk@myrealbox.com> for superreview: Bug 288906: Return null for MSAA name when no name explicitly set for HTML form control https://bugzilla.mozilla.org/show_bug.cgi?id=288906 Attachment 179538: If no name explictly set for form control, use SetIsVoid(null) https://bugzilla.mozilla.org/attachment.cgi?id=179538&action=edit ...

Controlling web control instances on Web Form
I have created a composite control, extending functionality of the Hidden Control. However, I would like to prevent the user from adding this control to the page multiple times. I only want one instance of the control on the Web Form. What setting in my project to I adjust to enable this functionality? I can not find it in any of the books that I have referenced. Is this a setting or is this code that has to be added to the inheriting class. Looks like there is no standard apporach. But I'd consider using static field to count number of created objects and throw exception if second object ...

Filling a textbox on a parent web user control from a child web form
Hi, I currently have a web user control (pf_imageselector.ascx) which is dynamically created (any number of times) on a parent web user control (pf_fillitems.ascx) which in turn has been loaded into a webform (default.aspx). On the user control is a text box called txbSelectedImage and a button. On click of the button run's this code: function OpenChild() { var strImageFile; var WinSettings = "height=580,width=630,status=yes,toolbar=no,menubar=no,location=no"; window.open("pf_stockimage.aspx", null, WinSettings); } Which obviously open a ch...

Getting the Selected Item of dropdownlist inside Web User Control on a Web Form
Ive got a dropdownlist control inside a web user control called Entity.ascx. This web user control is on a webform.aspx. In Entity.ascx class I created a SelectedEntity property that returns the selected item in the dropdownlist. Inside webform.aspx when btnGo is pushed I set a string and pass it in the url. I am trying to get the entity they selected via the property (SelectedEntity) inside Entity.ascx. As the SelectedEntity property tries to return the selected item in the dropdownlist I get this error: System.NullReferenceException: Object reference not set to an instance...

Where to get more control for web form?
I found that controls coming with ASP.NET are very less. Where to get more contol for web form? hello check these websites: 1- http://metabuilders.com/ 2- http://www.eworldui.net/default.aspx Good Luck.Bilal Hadiar, MCP, MCTS, MCPD, MCTMicrosoft MVP - Telerik MVP...

Web resources about - How to get the database column name that is bound to a FormView textbox control - asp.net.web-forms

Database - Wikipedia, the free encyclopedia
... requiring information. For example, modelling the availability of rooms in hotels in a way that supports finding a hotel with vacancies. Database ...

Database - Wikipedia, the free encyclopedia
A database is an organized collection of data . The data are typically organized to model aspects of reality in a way that supports processes ...

Five million customers affected by Vtech database hack
Toy and educational material seller Vtech has revealed five million customers were affected by a hack of its app database and has also suspended ...

Donald Trump wants "surveillance of certain mosques," database of refugees - Videos - CBS News
... rally in Birmingham, Alabama, Republican presidential candidate Donald Trump called for increased scrutiny over mosques, along with a database ...

IDG Contributor Network: Avoiding ginormous transaction logs with SharePoint databases
... why do we see these humongous transaction logs so often? I am going to blame it on a “misunderstanding” of how Microsoft describes a full database ...

Trump Wants A Database For All Syrian Refugees Who Enter America
Trump Wants A Database For All Syrian Refugees Who Enter America

Change your passwords: NexusMods suffers database breach
... security breach by posts on reddit. Cybersecurity firm REN-ISAC had apparently contacted several university IT departments about a database ...

VTech Admits Lack of Database Security Opened Door to Hack
A SQL injection, a common software flaw, was found to be the root cause in the VTech breach.

MapR And Big Data In The World's Largest Biometric Database Project
India?s Aadhaar project is one of the world?s most ambitious big data projects, aiming to collect, store, and utilize biometric information from ...

Trump calls for surveillance of some mosques, attempts to clarify remarks on Syrian database
Trump calls for surveillance of some mosques, attempts to clarify remarks on Syrian database

Resources last updated: 12/11/2015 5:26:35 PM