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>
<input name="ListView1$ctrl4$locationTextBox" type="text" id="ListView1_locationTextBox" />
</td>
<td>
<input name="ListView1$ctrl4$LogoTextBox_Logo" type="text" id="ListView1_LogoTextBox_Logo" />
</td>
<td>
<input name="ListView1$ctrl4$sequenceTextBox" type="text" id="ListView1_sequenceTextBox" />
</td>
<td>
<input name="ListView1$ctrl4$createrTextBox" type="text" id="ListView1_createrTextBox" />
</td>
<td>
<select name="ListView1$ctrl4$ddlInsertTemplate" id="ListView1_ddlInsertTemplate" onchange="changeVisible(this,ctrl4_LogoTextBox_Logo)">//这里生成的clientId和绿色部分的不一样
<option value="Text">文本链接</option>
<option value="pic">图片</option>
</select>
[解决办法]
http://topic.csdn.net/u/20110810/21/3071ac73-1ccd-4195-93fa-b227e40f05a8.html
如果之前方法不能解决 看这个