开发者

I am trying to assign a value to a gridview cell

how to assign a cell value to a grid view control cell from a string variable(local variable) using VB.net

After the gridview is populated, I would like to insert some data into 开发者_运维技巧one of the cells in a row in edit mode.


Create a label in the cell that is being bound, but leave it unbound. Then in the RowDataBound event you can find the label in the cell and populate it with the value you want.

private myString as String = "Some String"

... blah blah code ...

Protected Sub myGridview_RowDataBound(ByVal sender as Object, ByVal e as GridviewRowEventArgs) Handles myGridview.RowDataBound

    If e.Row.RowType = RowTypes.DataRow Then

        Dim index as Integer = 3    ' Make this the index of your cell 
        Dim lbl as Label = CType(e.Row.Cells(index).FindControl("myLabelName"), Label)
        lbl.Text = myString
    End If

End Sub

You can also do this with a literal, panel, etc. The key is to make sure you get the index right and make sure that you use the name provided in the ItemTemplate when using the FindControl method.


myGridView.Rows(x).Cells(y).Text = someValue

you might get an exception though, if this is a bound control.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜