简体   繁体   中英

Datatable data bind with textbox

need to get value from datatable and bind the value to textbox

            DataTable ff = new DataTable();
            DataColumn Regno = new DataColumn("Regno");
            ff.Columns.Add(Regno);
            DataRow row = ff.NewRow();
            var rg = (from data in db.receipts
                      select data.Regno).Max();

            row["Regno"] = rg + 1;
            ff.Rows.Add(row);
            txt_reciptno.DataBindings.Add("text", row, "Regno");

Why are you using DataTable ?? you can simply get rg via your query and then set the text property to rg + 1, something like following:

 text_recpitno.Text = (rg + 1).ToString();

Agreed with @Habib.OSU. But for the binding, try this:

txt_reciptno.DataBindings.Add("text", ff.DefaultView, "Regno");

I hope this article could help you. Data Binding in .Net

And in your case you need

txt_reciptno.DataBindings.Add("Text", ff, "Regno");

If you want to move to the next row , you should use

 var myCurrencyManager = (CurrencyManager)this.BindingContext[ff];

 myCurrencyManager.Position ++;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM