我正在寻求解决方案,基本上没有代码。我的问题是:Grid要绑定的数据源中的数据,需要翻译,如:性别-1-2-9,分别代表 男-女-未说明。我要绑定 1-2-9,显示 男-女-未说明,更新要同步。翻译部分,我已做完。我查阅了几乎所有的联机文档,没有特别地层的东西,如果您有,望不吝赐教。多谢

解决方案 »

  1.   

    使用DataView中的IIF请参考:
    http://expert.csdn.net/Expert/topic/1543/1543562.xml?temp=.6791345有问题再问
      

  2.   

    举个例子
    <IMG alt=单击看大图 src='<%# GetFileName(DataBinder.Eval(Container.DataItem, "PictureImage").ToString()) %>' border=0>
    ------------------
    帮助函数
    protected String GetFileName(String imageid)
    {
    String yearstr = imageid.Substring(0,4);
    ...
             return yearstr;
    }
      

  3.   

    我做的是System.Windows.Forms.DataGrid。
    我不是很明白jonsonzxw您的意思。
    timmy3310:您的建议不错,但有点问题:IFF(Sex = '1','男',''),这样的三目运算,对于符合条件的,目标列的对应值可以赋值,但其他的必须也要赋值结果是,目标列只能有两种值。请指点
    是否还有其他方法,及相关链接,望告知
      

  4.   

    IFF(Sex = '1','男',IIF(Sex='2','女',IIF(Sex='3','不男不女','又男又女')))可以嵌套的
      

  5.   

    timmy3310(tim):多谢!
    若有麻烦还望不吝赐教。
    再次谢谢!!!
      

  6.   

    timmy3310(tim):您好!
    问题又来了
    对于少量的嵌套,可以忽略性能上的影响;
    但是我的项目,需要几十甚至上百个嵌套
    我试过了,CPU几乎100%被占有
    可有他法???
    请赐教。谢谢!
      

  7.   

    (codeTable)
    coden     cname
    1         男
    2         女
    9         未说明
    (workerTalbe)
    wid       sex
    1         1
    2         1
    3         2不见得我每翻译一个人的Sex,
    都要 Select cname from codeTable where(coden = worker.sex)
    请指教。谢谢!!!
      

  8.   

    对,是不见得
    但是在你显示的地方,你可以select t1.*,t2.cname from workertable as t1,codetable as t2
    where t1.sex = t2.coden这样会查询出这样一个表:
    wid       sex  cname
    1         1    男
    2         1    男
    3         2    女这就好绑定了
      

  9.   

    这两张表,现在在DataSet中。
    请教在DataSet中的类似实现。
    多谢!!!
    “你显示的地方”是否可以理解为:
    显示多少翻译多少,翻屏事件触发翻译方法。
    小弟愚鲁,兄长见笑了。
    请赐教。谢谢!!!
      

  10.   

    IIF(条件,true,false)
    false单元中有没有DoNothing的方法
    即false什么都不返回
      

  11.   

    此示例演示如何从同一个 DataSet 填充两个单独的 DataGrid 控件。在这两个 DataGrid 控件之间建立了一种关系,因此当选定第一个 DataGrid 中的某个客户时,该客户的所有订单都显示在第二个 DataGrid 中。
    using Microsoft.Samples.Windows.Forms.Cs.MasterDetails.localhost;namespace  Microsoft.Samples.Windows.Forms.Cs.MasterDetails {    using System;
        using System.ComponentModel;
        using System.Diagnostics;
        using System.Windows.Forms;
        using System.Drawing;
        using System.Data;
        using System.Data.OleDb;
        using System.Web.Services.Protocols;
        public class CustomersForm : System.Windows.Forms.Form {
            private System.ComponentModel.Container components;
            private Microsoft.Samples.Windows.Forms.Cs.MasterDetails.Data.CustomersAndOrdersDataSet customersAndOrdersDataSet1;
            private System.Windows.Forms.StatusBar statusBar1;
            private System.Windows.Forms.Button buttonLoad;
            private System.Windows.Forms.Button buttonUpdate;
            private System.Windows.Forms.DataGrid dataGrid2;
            private System.Windows.Forms.DataGrid dataGrid1;        public CustomersForm() {            // Windows 窗体设计器支持所必需的
                InitializeComponent();        }        private void LoadData() {
                Cursor currentCursor = Cursor.Current;
                try {
                    Cursor.Current = Cursors.WaitCursor;                statusBar1.Text ="正在加载客户...";                //执行 WebService 返回数据集
                    CustomersAndOrders custList1 = new CustomersAndOrders();
                    DataSet ds1 = custList1.GetCustomersAndOrders();                //将新的数据集合并到 customersDataSet 中
                    customersAndOrdersDataSet1.Merge(ds1);                statusBar1.Text ="正在更新网格...";
                } finally {
                    Cursor.Current = currentCursor;
                    statusBar1.Text ="完成";
                }
            }        private void buttonLoad_Click(object sender, System.EventArgs e) {
                LoadData();
            }        private void buttonUpdate_Click(object sender, System.EventArgs e) {
                Cursor currentCursor = Cursor.Current;
                try {
                    this.BindingContext[customersAndOrdersDataSet1, "Customers"].EndCurrentEdit();                Cursor.Current = Cursors.WaitCursor;
                    statusBar1.Text ="正在更新客户...";
                    CustomersAndOrders custList1 = new CustomersAndOrders();                DataSet changesDS = customersAndOrdersDataSet1.GetChanges();                if (changesDS != null) {
                        //执行 WebService 以更新数据集
                        DataSet ds1 = custList1.UpdateCustomersAndOrders(changesDS);
                        statusBar1.Text = "正在更新网格...";
                        customersAndOrdersDataSet1.Merge(ds1,false);                    //查找错误 - 如果没有错误,则接受更改
                        if (customersAndOrdersDataSet1.HasErrors) {
                            MessageBox.Show("保存失败 - 检查行错误以获取详细信息", "保存失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        } else {
                            //接受所有的更改 - 此操作将数据集中的所有行都设置为
                            //unchanged 或“Original”状态
                            customersAndOrdersDataSet1.AcceptChanges();                    }
                    }            } catch(Exception ex) {
                    MessageBox.Show("保存失败:\n\n" + ex.ToString(), "保存失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
                } finally {
                    Cursor.Current = currentCursor;
                    statusBar1.Text ="完成";
                }
            }
      

  12.   

    /**
             * CustomersForm 重写 dispose 以便它可以清理
             * 组件列表。
             */
            public new void Dispose() {
                base.Dispose();
                components.Dispose();
            }
            private void InitializeComponent() {
                this.components = new System.ComponentModel.Container();
                this.dataGrid2 = new System.Windows.Forms.DataGrid();
                this.customersAndOrdersDataSet1 = new Microsoft.Samples.Windows.Forms.Cs.MasterDetails.Data.CustomersAndOrdersDataSet();
                this.dataGrid1 = new System.Windows.Forms.DataGrid();
                this.buttonLoad = new System.Windows.Forms.Button();
                this.buttonUpdate = new System.Windows.Forms.Button();
                this.statusBar1 = new System.Windows.Forms.StatusBar();            this.dataGrid1.BeginInit();
                this.dataGrid2.BeginInit();            if ( this.dataGrid1.TableStyles.Count == 0 ) {
                    this.dataGrid1.TableStyles.Add(new System.Windows.Forms.DataGridTableStyle());
                }
                if ( this.dataGrid2.TableStyles.Count == 0 ) {
                    this.dataGrid2.TableStyles.Add(new System.Windows.Forms.DataGridTableStyle());
                }            this.dataGrid2.Location = new System.Drawing.Point(8, 256);
                this.dataGrid2.Text = "dataGrid2";
                this.dataGrid2.Size = new System.Drawing.Size(584, 248);
                this.dataGrid2.TableStyles[0].PreferredColumnWidth = 50;
                this.dataGrid2.ForeColor = System.Drawing.SystemColors.WindowText;
                this.dataGrid2.TableStyles[0].SelectionBackColor = System.Drawing.SystemColors.ActiveCaption;
                this.dataGrid2.TabIndex = 1;
                this.dataGrid2.BackColor = System.Drawing.SystemColors.Window;
                this.dataGrid2.DataSource = customersAndOrdersDataSet1;
                this.dataGrid2.DataMember = "Customers.CustomersOrders";
                this.dataGrid2.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;            this.customersAndOrdersDataSet1.DataSetName = "CustomersAndOrdersDataSet";            this.dataGrid1.Location = new System.Drawing.Point(8, 8);
                this.dataGrid1.Text = "dataGrid1";
                this.dataGrid1.Size = new System.Drawing.Size(584, 240);
                this.dataGrid1.TableStyles[0].PreferredColumnWidth = 50;
                this.dataGrid1.ForeColor = System.Drawing.SystemColors.WindowText;
                this.dataGrid1.TableStyles[0].SelectionBackColor = System.Drawing.SystemColors.ActiveCaption;
                this.dataGrid1.TabIndex = 0;
                this.dataGrid1.BackColor = System.Drawing.SystemColors.Window;
                this.dataGrid1.AllowNavigation = false;
                this.dataGrid1.DataSource = customersAndOrdersDataSet1;
                this.dataGrid1.DataMember = "Customers";
                this.dataGrid1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
                this.Text = "客户订单";
                this.ClientSize = new System.Drawing.Size(600, 581);            this.buttonLoad.Location = new System.Drawing.Point(376, 512);
                this.buttonLoad.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
                this.buttonLoad.Size = new System.Drawing.Size(104, 40);
                this.buttonLoad.TabIndex = 2;
                this.buttonLoad.Text = "加载(&L)";
                this.buttonLoad.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
                this.buttonLoad.Click += new System.EventHandler(buttonLoad_Click);            this.buttonUpdate.Location = new System.Drawing.Point(488, 512);
                this.buttonUpdate.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
                this.buttonUpdate.Size = new System.Drawing.Size(104, 40);
                this.buttonUpdate.TabIndex = 2;
                this.buttonUpdate.Text = "更新(&U)";
                this.buttonUpdate.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
                this.buttonUpdate.Click += new System.EventHandler(buttonUpdate_Click);            this.statusBar1.Location = new System.Drawing.Point(0, 561);
                this.statusBar1.BackColor = System.Drawing.SystemColors.Control;
                this.statusBar1.TabIndex = 3;
                this.statusBar1.Text = "单击“加载”";
                this.statusBar1.Size = new System.Drawing.Size(600, 20);            this.Controls.AddRange(new System.Windows.Forms.Control[] {this.statusBar1,
                                                                              this.buttonLoad,
                                                                              this.buttonUpdate,
                                                                              this.dataGrid2,
                                                                              this.dataGrid1});
                this.dataGrid1.EndInit();
                this.dataGrid2.EndInit();
          }        [STAThread]
            public static void Main(string[] args) {
                Application.Run(new CustomersForm());
            }
        }
    }
      

  13.   

    参考:
    http://expert.csdn.net/Expert/topic/1543/1543562.xml?temp=.6791345
      

  14.   

    http://expert.csdn.net/Expert/topic/1543/1543562.xml?temp=.6791345