如何在vb.net中自动设置标签文本 [英] how to automatically set the Text Of a Label in vb.net

查看:366
本文介绍了如何在vb.net中自动设置标签文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表单中有10个标签和10个文本框。我正在尝试使用datagridview coloumns设置标签和文本框的文本我已经尝试了下面的代码,但它只为第一个标签设置文本而不是其余的..请指导先生通过这个家伙..

i have 10 labels and 10 textboxes in my form . i am trying to set the text of the labels and textbox using the datagridview coloumns i have tried the code below but it is setting the text only for the first label and not the rest..please guide mr through this guyz..

For Each row As DataGridViewRow In FormulativeDV.Rows
    If Not row.IsNewRow Then
        Lbl1.Text = (row.Cells(0).Value.ToString)
    End If
Next

推荐答案

您在代码中的某个时刻选择了Label从网格的第一行开始。在设置如下值之前,您只需要从每一行获取控件:

You have at some point in your code selected the Label from the first row in your grid. You simply need to grab the control from each row before you set the value like this:
For Each row As DataGridViewRow In FormulativeDV.Rows
   If Not row.IsNewRow Then
      Label lblCtl = (Label)row.FindControl("LabelName")
      If Not lblCtl = Nothing Then
         lblCtl.Text = (row.Cells(0).Value.ToString)
      End If
   End If
Next


这篇关于如何在vb.net中自动设置标签文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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