在Label中显示整个数据表 [英] Display whole datatable in Label

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

问题描述

大家好,

i我有一个显示名称,代码等的gridview ....其中我有一个名为''leave of leave''的字段,它有多个值。所以我是在gridview中显示日期作为模板字段。因为我正在将daticuler名称的日期输入到datatable中,现在我想显示整个datable。我无法弄清楚这一点,但任何人都可以建议我显示整个数据表的方式标签?以下是我使用的代码:





Hello everyone,
i am having gridview which displays name,code,etc....in which i have one field called ''date of leave'' which has multiple values.so i am displaying dates as template field in gridview.For that i am getting dates for perticuler name into datatable and now i want to display the whole datable.I am not able to figure this out,but can anyone suggest me the way to display whole datatable in label? Below is the code i have used:


SqlCommand cmd4 = new SqlCommand("select date1 from leave_rec where name='" + ename + "' AND MONTH(date1)='" + DropDownList3.SelectedValue + "' ", conn);

                SqlDataAdapter da4=new SqlDataAdapter(cmd4);
                DataTable dt=new DataTable();
                da4.Fill(dt);
                Label labd = (Label)e.Row.FindControl("dates");
                labd.Text = dt;/////here i want to assign label text.





在上面的代码中,''dates''是定义的标签的id在gridview中作为模板字段。



In the above code,''dates'' is the id of the label which is defined in gridview as templatefield.

推荐答案

即使你能做到 - 你可以做到,但它需要更多的工作 - 你会意识到数据将是没有任何格式显示?还是换行,除非你专门添加它们?



我不认为那是你想做的,所以我不会浪费时间去编码它适合你,但你所要做的就是循环遍历DataTable中的每一行,然后遍历行中的每个单元格,并将Value属性数据作为字符串添加到标签文本中。它看起来会很糟糕!
Even if you could do it - which you can, but it takes rather more work than that - you do realize that the data will be displayed without any formatting? Or line breaks, unless you specifically add them?

I don''t think that is what you want to do, so I won''t waste time by coding it for you, but all you have to do is loop through each row in the DataTable, then through each cell in the row and add the Value property data to the label text as a string. It''ll look horrible though!




请查看下面的代码,可能会帮助你解决问题。

Hi,
please look into follwoing code ,may be it can help u to fix your issue.
protected void gvdetails_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            #region Getting Data from database
            DBConnection bd = new DBConnection();
            DataSet ds = new DataSet();
            ds = bd.FromDatabase("Select VendorId from DailyIncome");
            #endregion
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string temp = "";
                Label LblError = (Label)e.Row.FindControl("lblShow");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {

                    temp += ds.Tables[0].Rows[i][0].ToString();

                }
                LblError.Text = temp;

            }
        }





jmd: - )



jmd:-)


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

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