如何将单元格添加到gridview行? [英] how do I prepend a cell to a gridview row?

查看:84
本文介绍了如何将单元格添加到gridview行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨伙计们(和女生)



感谢您抽出时间来帮助解决这个问题,请在盲目地粘贴指向Google相关文章的链接之前阅读问题,我花时间环顾四周(实际上是几天)。



我想做什么



在gridview中,我创建了一个新的动态列,其中包含一个swatch(一个div,其设置尺寸和背景颜色将根据单元格值而变化)。 'swatch'工作正常,但它在gridview的末尾



Hi guys (and girls)

Thanks for taking time to help on this, please read the question before blindly pasting a link to a non related article you googled, I have taken time to look around (for days actually).

What I am trying to do

In a gridview I am creating a new dynamic column that has a 'swatch' in it (a div with set dimensions and a background colour that will change depending on a cells value). The 'swatch' works fine but it's at the end of the gridview

e.Row.Cells.Add(SwatchCell)





我的问题



我遇到大问题它试图获得switch 在gridview的开头。现在我知道你喜欢代码示例所以我会放下我的GridView1_RowDataBound子的缩减版本。



这是我所拥有的代码的混蛋。 />




My Issue

where I am have big issues it trying to get the swatch at the beginning of the gridview. Now I know you like code examples so I'll put down a cut down version of my GridView1_RowDataBound sub.

Here is a bastardisation of the code i have.

 Protected Sub GridView1_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound

 Dim myDiv As HtmlGenericControl = New HtmlGenericControl("div")
            myDiv.ID = "Swatch"
            myDiv.InnerHtml = "   "
            myDiv.Style.Add("width", "15px")
            myDiv.Style.Add("height", "15px")
            myDiv.Style.Add("margin-left", "auto")
            myDiv.Style.Add("margin-right", "auto")

            Dim Swatchcolour As String = ""
            Dim MyElapseTime As Integer = Int32.Parse(Replace(e.Row.Cells(8).Text, " hour(s)", ""))

            Select Case MyElapseTime
                Case 0
                    Swatchcolour = "Green"
                Case 2 To 8
                    Swatchcolour = "Gold"
                Case Is < 24
                    Swatchcolour = "Orange"
                Case Else
                    Swatchcolour = "Red"
            End Select

            myDiv.Style.Add("background-color", Swatchcolour)

            Dim SwatchCell As New TableCell
            SwatchCell.Controls.Add(myDiv)
            e.Row.Cells.Add(SwatchCell)

End Sub





any帮助将不胜感激,作为一个注释我不能将样本添加到第一个单元格,因为它包含唯一标识符和一些代码我拿起该单元格的值以在其他地方使用'onclick'函数



亲切的问候



any help would be greatly appreciated, as a note I can't add the swatch to the first cell as this holds the unique identifier and some code i picking up the value of that cell to use an 'onclick' function elsewhere

kind regards

推荐答案

这篇关于如何将单元格添加到gridview行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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