本文介绍了在表格的一行中填写输入文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在表格的一行中填充输入文本.

how i can fill a Input text in a row in a table.

推荐答案

<table>
    <tr>
        <td>
            <form method="POST" action="">
                <input type="submit" value="Submit" name="sub">
                <input type="reset" value="Reset" name="rst">
            </form>
        </td>
    </tr>
</table>



OP:我看到这已经被否决了,但是目前,答案是对您的问题的最恰当的回答,因为它的措辞很明确.



OP: I see that this has been downvoted, but at the moment, the answer is the most appropriate response to your question as it''s curently phrased.


<form id="form1" runat="server">
  <div>
  </div>
  <asp:Table ID="Table1" runat="server" Height="185px" Width="341px">
  <asp:TableRow>
  <asp:TableCell ID="r1">
      <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></asp:TableCell>
  </asp:TableRow>
  <asp:TableRow ID="r2">
  <asp:TableCell ID="txtcell">
      <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></asp:TableCell>
  </asp:TableRow>
  </asp:Table>

<hr />


  <table id="Table2" runat="server">
  <tr>
  <td> <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox></asp:TableCell></td>
  </tr>
  <tr>
  <td> <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox></asp:TableCell></td>
  </tr>
  </table>

  <br />
  <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
  </form>










将此放在您的代码后面

受保护的void Button1_Click(对象发送者,EventArgs e)
{TextBox txt =(TextBox)FindControlRecursive(Table1,"TextBox1");
TextBox txt2 =(TextBox)FindControlRecursive(Table1,"TextBox2");
TextBox txt3 =(TextBox)FindControlRecursive(Table2,"TextBox3");
TextBox txt4 =(TextBox)FindControlRecursive(Table2,"TextBox4");
txt.Text ="yourvalue";
txt2.Text ="yourvalue2";
txt3.Text ="yourvalue3";
txt4.Text ="yourvalue4";
}


公共控件FindControlRecursive(控件根,字符串ID)
{
如果(Root.ID == Id)
返回根;
foreach(Root.Controls中的Control Ctl)
{
控件FoundCtl = FindControlRecursive(Ctl,Id);
如果(FoundCtl!= null)
返回FoundCtl;
}
返回null;
}










put this in your code behind

protected void Button1_Click(object sender, EventArgs e)
{ TextBox txt = (TextBox)FindControlRecursive(Table1, "TextBox1");
TextBox txt2 = (TextBox)FindControlRecursive(Table1, "TextBox2");
TextBox txt3 = (TextBox)FindControlRecursive(Table2, "TextBox3");
TextBox txt4 = (TextBox)FindControlRecursive(Table2, "TextBox4");
txt.Text = "yourvalue";
txt2.Text = "yourvalue2";
txt3.Text = "yourvalue3";
txt4.Text = "yourvalue4";
}


public Control FindControlRecursive(Control Root, string Id)
{
if (Root.ID == Id)
return Root;
foreach (Control Ctl in Root.Controls)
{
Control FoundCtl = FindControlRecursive(Ctl, Id);
if (FoundCtl != null)
return FoundCtl;
}
return null;
}


这篇关于在表格的一行中填写输入文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 21:42
查看更多