日期:2014-05-17  浏览次数:20521 次

asp.net中ListView控件的问题。好纠结~~
asp.net的listView控件:

<InsertItemTemplate>
  <tr style="">
  <td>
  <asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="插入" />
  <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="清除" />
  </td>
  <td>
  <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
  </td>
  <td>
  <asp:TextBox ID="locationTextBox" runat="server" 
  Text='<%# Bind("location") %>' />
  </td>
  <td>
  //下面的ID用于获取到该TextBox
  <asp:TextBox ID="LogoTextBox_Logo" runat="server" Text='<%# Bind("Logo") %>' />
  </td>
  <td>
  <asp:TextBox ID="sequenceTextBox" runat="server" 
  Text='<%# Bind("sequence") %>' />
  </td>
  <td>
  <asp:TextBox ID="createrTextBox" runat="server" Text='<%# Bind("creater") %>' />
  </td>
  <td>
  <asp:DropDownList ID="ddlInsertTemplate" runat="server">
  <asp:ListItem value="Text">文本链接</asp:ListItem>
  <asp:ListItem value="pic">图片</asp:ListItem>
  </asp:DropDownList>
  </td>
  </tr>
  </InsertItemTemplate>


此处是后台代码:

protected void ListView1_ItemCreated(object sender, ListViewItemEventArgs e)
  {
  if (e.Item.ItemType==ListViewItemType.InsertItem)
  {
  //这里根据下拉控件的ID获取到了下拉控件的对象
  DropDownList ddl = (DropDownList)e.Item.FindControl("ddlInsertTemplate");
 //这里也是找到插入数据时要获取的textBox的对象,红色字体的ID和上面<InsertItemTemplate>的TextBox的Id是一样的  
  TextBox tb = (TextBox)e.Item.FindControl("LogoTextBox_Logo");
  //下面红色部分生成的ID和在HTML页面渲染成的ID不一样。求解
  ddl.Attributes["onchange"] = "changeVisible(this,"+tb.ClientID+")";
  }
  }
后台代码中tb对象是不是空,并且生成的ClientId和在页面生成的ID不一样


以下是渲染成的HTML的部分代码
<tr style="">
  <td>
  <input type="submit" name="ListView1$ctrl4$InsertButton" value="插入" id="ListView1_InsertButton" />
  <input type="submit" name="ListView1$ctrl4$CancelButton" value="清除" id="ListView1_CancelButton" />
  </td>
  <td>
  <input name="ListView1$ctrl4$NameTextBox" type="text" id="ListView1_NameTextBox" />
  </td>
  <td>