如何使用具有多个数字的数据填充文本框? [英] How to populate textboxes with data that has multi numbers?

查看:58
本文介绍了如何使用具有多个数字的数据填充文本框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于填充数据库中数据的Web表单。那部分工作正常。我有一个具有用户ID和不同单位ID的数据库。我知道我可以创建一个网格视图来显示该用户的所有数据,但我想知道是否有办法将其用于文本框?



示例:

 USER |单位ID |车|卡车| 
100 | 200 | 1 | 2 |
100 | 300 | 3 | 4 |
100 | 400 | 6 | 7 |





如何将这些数据填充到文本框中?



以下是我用来填充文本框的当前代码:

  if (TextBoxINST_ID.Text.Trim() .Length >   0 
{
SqlConnection con3 = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings [ HotConnectionString]的ConnectionString)。
con3.Open();

SqlCommand scmd3 = new SqlCommand( 选择FT_UNDERGR,FT_GRAD,FTE_UNDERG,FTE_GRAD,NON_CREDIT,TOTAL_FTE,FCFTUHC,FCFTPBHC,FCPTUHC,FCPTPBHC,NCHC,FTE40,HC50,FTE4050,UnderG12,Postb9,Total123b4b,表88中的THCAS,其中User_ID =' + TextBoxUser_ID.Text + ',con3);
SqlDataReader dr3 = scmd3.ExecuteReader();
if (dr3.Read())
{
TextBoxFTUG2.Text = dr3 [ FT_UNDERGR]。ToString();
TextBoxFTG2.Text = dr3 [ FT_GRAD]。ToString();
TextBoxTHUGDR2.Text = dr3 [ FTE_UNDERG]。ToString();
TextBoxTHGDR2.Text = dr3 [ FTE_GRAD]。ToString();
TextBoxNCCDR2.Text = dr3 [ NON_CREDIT]。ToString();
TextBoxTCNC2.Text = dr3 [ TOTAL_FTE]。ToString();
TextBoxTNFUG2.Text = dr3 [ FCFTUHC]。ToString();
TextBoxTNFG2.Text = dr3 [ FCFTPBHC]。ToString();
TextBoxTNCPUG2.Text = dr3 [ FCPTUHC]。ToString();
TextBoxTNCPG2.Text = dr3 [ FCPTPBHC]。ToString();
TextBoxTNNCC2.Text = dr3 [ NCHC]。ToString();
TextBoxFTE402.Text = dr3 [ FTE40]。ToString();
TextBoxHC502.Text = dr3 [ HC50]。ToString();
TextBoxFTE40502.Text = dr3 [ FTE4050]。ToString();
TextBoxTHUG2.Text = dr3 [ UnderG12]。ToString();
TextBoxTHG2.Text = dr3 [ Postb9]。ToString();
TextBoxT12342.Text = dr3 [ Total123b4b]。ToString();
TextBoxTHCAS2.Text = dr3 [ THCAS]。ToString();
ButtonSubmit2.Visible = true ;

}
con3.Close();
dr3.Close();

解决方案

严重吗?我不会,我会使用Gridview或HTML表。



另一个解决方案(至少使事情更整洁)将是创建一个自定义控件包含一行适当数量的文本框,并为每一行动态创建其中一个。



但我会选择GridView。

I have a web form that populates data from the database. That part works fine. I have a database that has a User ID and different Unit IDs. I know I could just make a Grid View to display all of the data just for that user but I wanted to know if there is a way to do it to a textbox?

Example:

USER | Unit ID | Car | Truck |
100  | 200     |  1  |   2   |
100  | 300     |  3  |   4   |
100  | 400     |  6  |   7   |



How can this data be populated into textboxes?

Here is the current code I use to populate textboxes:

if (TextBoxINST_ID.Text.Trim().Length > 0)
            {
                SqlConnection con3 = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
                con3.Open();

                SqlCommand scmd3 = new SqlCommand("Select FT_UNDERGR, FT_GRAD, FTE_UNDERG, FTE_GRAD, NON_CREDIT, TOTAL_FTE, FCFTUHC, FCFTPBHC, FCPTUHC, FCPTPBHC, NCHC, FTE40, HC50, FTE4050, UnderG12, Postb9, Total123b4b, THCAS from Table88 where User_ID = '" + TextBoxUser_ID.Text + "'", con3);
                SqlDataReader dr3 = scmd3.ExecuteReader();
                if (dr3.Read())
                {
                    TextBoxFTUG2.Text = dr3["FT_UNDERGR"].ToString();
                    TextBoxFTG2.Text = dr3["FT_GRAD"].ToString();
                    TextBoxTHUGDR2.Text = dr3["FTE_UNDERG"].ToString();
                    TextBoxTHGDR2.Text = dr3["FTE_GRAD"].ToString();
                    TextBoxNCCDR2.Text = dr3["NON_CREDIT"].ToString();
                    TextBoxTCNC2.Text = dr3["TOTAL_FTE"].ToString();
                    TextBoxTNFUG2.Text = dr3["FCFTUHC"].ToString();
                    TextBoxTNFG2.Text = dr3["FCFTPBHC"].ToString();
                    TextBoxTNCPUG2.Text = dr3["FCPTUHC"].ToString();
                    TextBoxTNCPG2.Text = dr3["FCPTPBHC"].ToString();
                    TextBoxTNNCC2.Text = dr3["NCHC"].ToString();
                    TextBoxFTE402.Text = dr3["FTE40"].ToString();
                    TextBoxHC502.Text = dr3["HC50"].ToString();
                    TextBoxFTE40502.Text = dr3["FTE4050"].ToString();
                    TextBoxTHUG2.Text = dr3["UnderG12"].ToString();
                    TextBoxTHG2.Text = dr3["Postb9"].ToString();
                    TextBoxT12342.Text = dr3["Total123b4b"].ToString();
                    TextBoxTHCAS2.Text = dr3["THCAS"].ToString();
                    ButtonSubmit2.Visible = true;

                }
                con3.Close();
                dr3.Close();

解决方案

Seriously? I wouldn't, I'd use a Gridview, or an HTML table.

The other solution (which at least makes things tidier) would be to create a custom control which contains the appropriate number of textboxes for a row, and dynamically create one of those for each row.

But I'd go with the GridView.


这篇关于如何使用具有多个数字的数据填充文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆