0

I am a novice with ASP.NET, and I am wondering if the following is possible. I have an application that is bound to a data source (MS Access) using OldDbDataAadpter, and works ok However, I want to be able to display ONE of an number of table fields based on user input (from a drop down list). The idea is that user selects one of (a possible 10) languages at runtime, and have the Gridview display only that field.
If you can ignore the structure of the database for the moment (it is a legacy issue), the table has a number of fields (Index, Name, etc..) and then a field for one of 10 languages (such as en-us, de, es, fr, ect..).
The following section works fine (the variable "lang" is filled from the dropdown list at runtime)

       string qryStr = "select PIndex, TName, Component, " + lang  " from MyTbles";


        GlobalClass.adap = new OleDbDataAdapter(qryStr, con);

        OleDbCommandBuilder bui = new OleDbCommandBuilder(GlobalClass.adap);

        GlobalClass.dt = new DataTable();

        GlobalClass.adap.Fill(GlobalClass.dt);

        GridView1.DataSource = GlobalClass.dt;

        GridView1.DataBind();

GlobalClass.cs is as follows: public class GlobalClass {

    public static OleDbDataAdapter adap;

    public static DataTable dt;

    // Stored image path before updating the record

}

The problem is the ASP code appears to require the EXACT fieldname when it is bound. This is a section of the ASP file :

 Text='<%#Bind("Component") %>'

This shows how the "Component" field is bound to the Gridview textbox. My question is: Is it possible to use a variable name in the "Bind" sections above? I want this ASP code to be able to find and resolve a variable from the .CS code behind section.
I am not expecting anyone to show me how, but I would like to know if this is possible (and the relevant classes I should be looking at..) Many thanks..

0

1 Answer 1

1

Why not just do

string qryStr = "select PIndex, TName, Component, " + lang " as SelectedLang from MyTbles";

then

Text='<%#Bind("SelectedLang") %>'

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.