1
经过一些帮助和审查的代码后,我得到了这个工作没有任何错误。但是,当我按下按钮什么都没有发生时,文本框不会更新。回应DataList中的按钮事件
我也是如何访问DataList中的数据,以便我可以在“DataList1_ItemCommand”函数中操作它。
<p>
<asp:TextBox ID="NameTextBox" runat="server" CssClass="textEntry"
TextMode="SingleLine" Rows="0" Height="20px" Width="250px" Enabled="False"></asp:TextBox>
<asp:DataList
ID="DataList1"
runat="server"
RepeatColumns="1" CellPadding="4" ForeColor="#333333"
GridLines="Both" Height="132px" Width="427px">
<HeaderTemplate>
Data
</HeaderTemplate>
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "ref") %>
<%# DataBinder.Eval(Container.DataItem, "name") %>
<%# DataBinder.Eval(Container.DataItem, "city") %>
<%# DataBinder.Eval(Container.DataItem, "ip") %>
<%# DataBinder.Eval(Container.DataItem, "timestamp") %>
<asp:Button ID="manage" runat="server" CommandName="manageWiki" Text="Granska" Visible="True" />
</ItemTemplate>
<AlternatingItemStyle BackColor="White" ForeColor="#284775" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle Font-Bold="true" Font-Names="Arial" BackColor="#5D7B9D"
ForeColor="White" />
<ItemStyle Font-Names="Arial" Font-Size="Small" BackColor="#F7F6F3"
ForeColor="#333333" />
<SelectedItemStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
</asp:DataList>
</p>
而后面的代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//getSuggestions fill the DataList with data
getSuggestions("SELECT [ref], [city], [name], [timestamp], [ip] FROM [table1] ORDER BY timestamp");
}
}
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "manageWiki")
{
//Just update the TextBox
NameTextBox.Text = "ref that is inside the Datalist1";
}
}
好吧我想通了你的意思是”如果你修改了通过客户端脚本提供的数据并发布回来并且与ViewState期望的内容不匹配,通常会发生这种错误“作品。我将编辑上面的代码。 – Mikael 2010-08-10 23:27:42
@Mikael所以你的问题解决了吗?如果这个答案帮助你不要忘记把它设置为接受的答案,或者甚至给它一个投票:) – Kelsey 2010-08-11 02:06:58
它部分解决了,但我意识到我问的问题是错误的,所以我更新了它,也许我应该已经开始一个新的问题? – Mikael 2010-08-11 07:38:17