想办法把你的DIV块用个服务器端控件替换掉

解决方案 »

  1.   

    how did you hide TextBox1? don't use Visible=false, use style="display:none"
      

  2.   

    try<form runat=server id=form1>
    <div onclick="hid.value='123';txt1.value='456'; form1.submit()">
     hello word, click me!
     <input type=hidden id=hid runat=server />
     <asp:TextBox id=txt1 runat=server style="display:none" />
    </div>
    </form>
    <script language=c# runat=server>
    void Page_Load(Object o, EventArgs e)
    {
      if (IsPostBack)
      {
    Response.Write(hid.Value + ":" + txt1.Text);
      }
    }
    </script>
      

  3.   

    谢谢两位。其实我是想在DataGrid的Header上放个Div块,然后点DIV后排序,刷新整个页面.难道Div中只能放服务器端恐件?提交时才能取得其他TextBox的内容?
      

  4.   

    you can put anything there, but since the header is part of the datagrid, you cannot just use TextBox1.Text, you  need to do something likeTable t = (Table)DataGrid1.Controls[0];
    TableRow tr = t.Rows[0];
    TextBox tb = (TextBox)tr.FindControl("TextBox1");
    ....for example:<%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.SqlClient" %>
    <Script language="C#" runat="server">
    void Page_Load(Object o, EventArgs e)
    {
    if (!IsPostBack)
    {
    SqlDataAdapter da = new SqlDataAdapter("select * from authors",
    "Server=localhost;Database=pubs;UID=sa;PWD=;");
    DataSet ds = new DataSet();
    da.Fill(ds,"authors"); DataGrid1.DataSource = ds.Tables["authors"].DefaultView;
    DataGrid1.DataBind();

    }
    else
    {
    Table t = (Table)DataGrid1.Controls[0];
    TableRow tr = t.Rows[0];
    TextBox tb = (TextBox)tr.FindControl("TextBox1");
    HtmlInputHidden hhi = (HtmlInputHidden)tr.FindControl("hid");
    Response.Write(String.Format("{0}:{1}<BR>", tb.Text, hhi.Value));
    }
    }</script>
    <form runat="server">
    <asp:datagrid id="DataGrid1" runat="server" GridLines="Both">
    <Columns>
    <asp:TemplateColumn HeaderText="Test">
    <HeaderTemplate>
    <div onclick="this.all.tags('INPUT')[0].value='123';this.all.tags('INPUT')[1].value='456'; document.forms[0].submit()">
      hello word, click me!
      <input type=hidden id=hid runat=server />
      <asp:TextBox id=TextBox1 runat=server/>
                  </div>
    </HeaderTemplate>
    <ItemTemplate>
    test
    </ItemTemplate>
    </asp:TemplateColumn>
    </Columns>
    </asp:datagrid>
    <asp:Button id=btn runat=server Text="submit" />
    </form>
      

  5.   

    不好意思 思归您好像理解错了我的意思了。
    我的TextBox1是不是放在DataGrid中的。其实最主要的原因就是使用js的submit()只能用Requset.Form得到,而平常使用的TextBox1.Text得不到数据。
      

  6.   

    show your code, let's see what's wrong