在datagridview特定列中显示数据 [英] Displaying data in datagridview specific column

查看:98
本文介绍了在datagridview特定列中显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在使用单独的方法和处理过的proc加载datagridview.
我的问题是,这些值现在在第一个列中彼此下方填充,我需要将这些值加载到其指定的列中.

如何指定值应加载到哪一列.

EDIS_Status应该在我的datagridview的第二列中加载,kW111550在下一列中加载第三列,依此类推...

Hi all,

I am loading a datagridview using separate methods and stroed procs.
My problem is that the values is now populating underneath each other in the first colum, I need the values to load in their specified columns.

How would I be able to specifiy in which column the values should load.

EDIS_Status should load in the 2nd column of my datagridview, kW111550 in the next column the 3rd column etc...

 private void LoadGrid()
        {
            try
            {
                clsConnection data = new clsConnection();
                SqlCommand sqlcomm = new SqlCommand();
                DataTable dt = new DataTable();

                sqlcomm.Connection = data.connection;
                sqlcomm.CommandType = CommandType.StoredProcedure;
                sqlcomm.CommandText = "usp_LoadProfileGrid2";
                sqlcomm.Parameters.Add("@MeterID", SqlDbType.Int).Value = iMeterID;

                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = sqlcomm;
                da.Fill(dt);
                dgvLoadProfile.ReadOnly = true;

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    dgvLoadProfile.Rows.Add(dt.Rows[i]["EDIS_Status"].ToString());
                }           

                clsConnection data2 = new clsConnection();
                SqlCommand sqlcomm2 = new SqlCommand();
                DataTable dt2 = new DataTable();

                sqlcomm2.Connection = data2.connection;
                sqlcomm2.CommandType = CommandType.StoredProcedure;
                sqlcomm2.CommandText = "usp_LoadProfileGrid3";
                sqlcomm2.Parameters.Add("@MeterID", SqlDbType.Int).Value = iMeterID;

                SqlDataAdapter da2 = new SqlDataAdapter();
                da2.SelectCommand = sqlcomm2;
                da2.Fill(dt2);
                dgvLoadProfile.ReadOnly = true;

                for (int i = 0; i < dt2.Rows.Count; i++)
                {
                    dgvLoadProfile.Rows.Add(dt2.Rows[i]["kW111550"].ToString());
                }
catch (Exception excException)
            {
                MessageBox.Show(excException.Message, excException.Source, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }



谢谢您的帮助!!!!



Thanks any help would be appriciated!!!

推荐答案

<asp:TemplateField HeaderText="ProgrammeID" Visible="false">
                        <ItemTemplate>
                            <asp:Label ID="lblProgID" runat="server" Text='<%# Bind("ProgrammeID") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>


试试这个代码.


try this code.




我想您的for循环中有问题.

Hi,

I guess there is a problem in your for loop.

for (int i = 0; i < dt.Rows.Count; i++)
               {
                   dgvLoadProfile.Rows.Add(dt.Rows[i]["EDIS_Status"].ToString());
               }




在这里,您正在遍历数据表行,但未遍历网格.

检查是否可行.




Here, you are looping through the datatable rows but not looping through the grid.

check if this works.

for (int i = 0; i < dt.Rows.Count; i++)
               {
                   dgvLoadProfile.Rows[i].Add(dt.Rows[i]["EDIS_Status"].ToString());
               }


strcValue = "";
                    strcValue = dgvLoadProfile["cTime", 0].Value.ToString();

                    dgvLoadProfile["cEDIS_Status", 0].Value = strcValue;
                    strcValue = "";
                    dgvLoadProfile["cTime", 0].Value = strcValue;


这篇关于在datagridview特定列中显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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