我无法获取label.text的详细信息,但能够第一次获取文本框值 [英] I'm unable to get the details of my labels.text , but are able to get the text box value the first time

查看:134
本文介绍了我无法获取label.text的详细信息,但能够第一次获取文本框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

recently I changed my GridView so it was able to add rows dynamically. The problem is, when I insert the data, I'm getting blank value at first.

I'm unable to get the details of my labels.text , but are able to get the text box value the first time. When the loop continues, I get 1 row of value from the label and 2 rows of value from the text box.







GridViewRow row = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal);

    TableHeaderCell cell = new TableHeaderCell();
    cell.Text = "Details";
    cell.ColumnSpan = 3;
    row.Controls.Add(cell);


    cell = new TableHeaderCell();
    cell.Text = "Year 2018";
    cell.ColumnSpan = 4;
    row.Controls.Add(cell);

    cell = new TableHeaderCell();
    cell.ColumnSpan = 4;
    cell.Text = "Year 2019";
    row.Controls.Add(cell);

     cell = new TableHeaderCell();
    cell.Text = "Others";
    cell.ColumnSpan = 3;
    row.Controls.Add(cell);





我尝试过:





What I have tried:

Label CenterId = (Label)row.FindControl("CenterId") as Label;
              string CenterId_no = Convert.ToString(CenterId.Text);


            TextBox txt_lastyearonDate = (TextBox)row.FindControl("txt_lastyearonDate") as TextBox;

            float py_ondte = float.Parse(txt_lastyearonDate.Text);

推荐答案

你没有告诉我们任何具有任何特定ID的控件 - 那么是什么让你认为FindControl会返回任何内容?

尝试
You don't show us any control with any specific ID - so what makes you think that FindControl will return anything?
Try
Label CentreID = row.Cells[1].Controls[0] as Label;




Or

string s = (string) row.Cells[1].Value;


这篇关于我无法获取label.text的详细信息,但能够第一次获取文本框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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