0

我很难弄清楚这一点,而且应该不会太难。我想textbox从我的数据库或从label(标签已经从数据库中提取信息,因此基本上将标签中的内容复制到文本框中)填充我的。我正在使用 a GridView,这是我一直在尝试的代码:

C#:

for (int i = 0; i < GridView1.Rows.Count; i++)
            {

                TextBox timeR = GridView1.Rows[i].FindControl("rTime") as TextBox;
                Label timeRL = GridView1.Rows[i].FindControl("labelRunScore") as Label;
                if (timeR.Text == "")
                {
                    timeR.Text = timeRL.Text;

                }

            }

.aspx:

<asp:TemplateField  HeaderText = "Run Time">
        <ItemTemplate>
            <asp:Label ID="labelRunScore" Visible="true" runat="server" Text='<%# Eval("rTime") %>' />
        </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Run Time">
        <ItemTemplate>
           <div style="display:none"> <asp:TextBox ID="rTime" runat="server" type="number" Text='<%# Eval("rTime") %>' ></asp:TextBox></div>
           <input onblur="document.getElementById('<%# ((GridViewRow)Container).FindControl("rTime").ClientID %>').value = this.value" 
    type="number" style="width: 100px; height: 31px;" />
        </ItemTemplate>
    </asp:TemplateField>
4

0 回答 0