当前位置: 代码迷 >> .NET新技术 >> (急)关于DataList怎样绑定后台方法的有关问题
  详细解决方案

(急)关于DataList怎样绑定后台方法的有关问题

热度:105   发布时间:2016-04-25 01:47:04.0
(急)关于DataList怎样绑定后台方法的问题
HTML code
<asp:DataList ID="DataList1" runat="server">    <ItemTemplate>          <table cellpadding="5" cellspacing="5">            <tr>                <th style="background-color:#d57d69; width:150px;">奖励点数</th>                <th style="background-color:#d469d5;width:150px;">人次</th>                <th style="background-color:#69b5d5;width:150px;">产生点数(Pt)</th>                <th style="background-color:#69b5d5;width:150px;">说明</th>            </tr>            <tr>                <td style="color:#d57d69; background-color:#ffffff"><asp:TextBox ID="txtlevel20" runat="server" Text="2" Width="20"></asp:TextBox></td>                <td style="color:#d57d69; background-color:#ffffff"><%#DataBinder.Eval(Container.DataItem, "P_lvl20")%></td>                <td style="color:#d469d5; background-color:#ffffff"><%# gettotal(???????) %></td>                <td style="color:#69b5d5; background-color:#ffffff">Level - 20 Bonus</td>            </tr>        </table>            </ItemTemplate>    </asp:DataList>



gettotal()这个方法是写在该页面的CS文件中
C# code
 public string gettotal(string txt,string num)    {        try        {            return Convert.ToString(Convert.ToInt32(txt) * Convert.ToInt32(num));        }        catch (Exception e)        {           return "请输入数字";        }    }



该方法的参数:
txt为txtlevel20.Text
num为"><%#DataBinder.Eval(Container.DataItem, "P_lvl20")%>

在页面上要怎么写呀??请指教

------解决方案--------------------
<%# gettotal("2", Eval("P_lvl20").ToString()) %>
------解决方案--------------------
txt参数是如果是这个文本框的值,好像没什么意义吧。。。每次载入的时候,都是取文本框已经载入的值,文本框的值应该也是一个绑定的字段吧,,,你可以将txt参数也绑定一个字段
------解决方案--------------------
txt为txtlevel20.Text
这个不行,因为你绑定的时候 txt 没有设置初值,内容是空. 就算设置初值 和你当前的期望也不一致

num为"><%#DataBinder.Eval(Container.DataItem, "P_lvl20")%>

这个可以

<%# gettotal((Eval("P_lvl20")??"").ToString()) %>
------解决方案--------------------
<td style="color:#d469d5; background-color:#ffffff"><%# gettotal(???????) %></td>

这个不这么写

给同一行 tr 中的 textbox 增加 change 客户端事件,这样在触发事件时改动该单元格的内容即可

------解决方案--------------------
恩,就是这个意思。
  相关解决方案