标题:求助:请高手帮忙看看问题出在哪里
只看楼主
Issac_abc
Rank: 4
来 自:河南
等 级:业余侠客
威 望:2
帖 子:155
专家分:218
注 册:2010-6-17
结帖率:76.19%
已结贴  问题点数:20 回复次数:4 
求助:请高手帮忙看看问题出在哪里
更新时没有得到  CommontName、Alias 、Overview、Record  的值
 <asp:DataList ID="DataList1" runat="server"
                Width="100%" oneditcommand="DataList1_EditCommand"
                onupdatecommand="DataList1_UpdateCommand" DataKeyField="Id">
                <ItemTemplate>
                    <table style=" width:98%; border:0px;">
                        <tr>
                            <td><font color="gray">品名:</font></td>
                        </tr>
                        <tr>
                            <td>
                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                <font color="gray"><asp:Label ID="Label2" runat="server" Text='<%# Eval("CommontName") %>' /></font>
                            </td>
                        </tr>
                        <tr><td>&nbsp;</td></tr>
                        <tr>
                            <td><font color="gray">别名:</font></td>
                        </tr>
                        <tr>
                            <td>
                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                <font color="gray"><asp:Label ID="Label3" runat="server" Text='<%# Eval("Alias") %>' /></font>
                            </td>
                        </tr>
                        <tr><td>&nbsp;</td></tr>
                        <tr>
                            <td><font color="gray">概述:</font></td>
                        </tr>
                        <tr>
                            <td>
                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                <font color="gray"><asp:Label ID="Label4" runat="server" Text='<%# Eval("Overview") %>' /></font>
                            </td>
                        </tr>
                        <tr><td>&nbsp;</td></tr>
                        <tr>
                            <td>
                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                <font color="gray"><asp:Label ID="Label5" runat="server" Text='<%# Eval("Record") %>' /></font>
                            </td>
                        </tr>
                        <tr><td>&nbsp;</td></tr>
                        <tr>
                            <td align="left">
                                <asp:LinkButton CommandName="Edit" ID="Edit_But" ForeColor="#003366" runat="server">编辑</asp:LinkButton>
                            </td>
                        </tr>
                    </table>        
                </ItemTemplate>
            
                <EditItemTemplate>
                    <table style=" width:98%; border:0px;">
                        <tr>
                            <td>
                                <font color="gray">品名:</font>
                                 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                <font color="gray">
                                <asp:TextBox ID="txtName" runat="server" Text='<%# Bind("CommontName") %>'></asp:TextBox>
                                </font>
                            </td>
                        </tr>
                        <tr><td>&nbsp;</td></tr>
                        <tr>
                            <td>
                                <font color="gray">别名:</font>
                                 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                <font color="gray"><asp:TextBox ID="txtAlias" runat="server" Text='<%# Bind("Alias") %>' /></font>
                            </td>
                        </tr>
                        <tr><td>&nbsp;</td></tr>
                        <tr>
                            <td>
                                <font color="gray">概述:</font>
                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                <font color="gray"><asp:TextBox ID="txtOverView" runat="server" Text='<%# Bind("Overview") %>' /></font>
                            </td>
                        </tr>
                        <tr><td>&nbsp;</td></tr>
                        <tr>
                            <td>
                                <font color="gray">详细信息:</font>
                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                <font color="gray">
                                <FTB:FreeTextBox ID="ftbRecord" runat="server" Text='<%# Bind("Record") %>'>
                                </FTB:FreeTextBox>
                                </font>
                            </td>
                        </tr>
                        <tr><td>&nbsp;</td></tr>
                        <tr>
                             <td align="left" bgcolor="#E8F0F7">
                                 <asp:LinkButton ID="LinkButton1" runat="server"
                                  CommandName="Update" ForeColor="#003366">更新</asp:LinkButton>
                            </td>
                        </tr>
                    </table>        
            </EditItemTemplate>
        </asp:DataList>







后台代码:

 //点击编辑
    protected void DataList1_EditCommand(object source, DataListCommandEventArgs e)
    {
        this.DataList1.EditItemIndex = e.Item.ItemIndex;
        this.DataList1.DataBind();
    }

    //点击修改
    protected void DataList1_UpdateCommand(object source, DataListCommandEventArgs e)
    {
        Varieties model = new Varieties();
        
       = ((TextBox)e.Item.FindControl("txtName")).Text.Trim();
        model.Alias = ((TextBox)e.Item.FindControl("txtAlias")).Text.Trim();
        model.Overview = ((TextBox)e.Item.FindControl("txtOverView")).Text.Trim();
        model.Record = ((FreeTextBox)e.Item.FindControl("ftbRecord")).Text.Trim();
        model.Id = (int)this.DataList1.DataKeys[e.Item.ItemIndex];
        if (varietiesMessage.modifyVarietes(model))
        {
            Response.Write("<script>alert('操作成功!');window.location.href='Varietie.aspx';</script>");
        }
        else
        {
            Response.Write("<script>alert('服务器繁忙请稍候执行此操作!');</script>");
        }
    }
搜索更多相关主题的帖子: 品名 server border color 
2010-08-24 09:45
NewDeveloper
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:48
专家分:159
注 册:2010-7-2
得分:6 
Eval 单向绑定:数据是只读的
Bind 双向绑定:数据可以更改,并返回服务器端,服务器可以处理更改后的数据,如存入数据库.
你在后台里更新了,把Bind该为Eval试试
2010-08-24 10:19
冰镇柠檬汁儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:北京
等 级:版主
威 望:120
帖 子:8074
专家分:6657
注 册:2005-11-7
得分:6 
好像没贴出来数据绑定的代码?

本来无一物,何处惹尘埃
It is empty at all here, Why pm 2.5 is so TMD high!
2010-08-24 12:18
qingshuiliu
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:17
帖 子:323
专家分:1538
注 册:2009-12-28
得分:6 
首先,Bind方法是没有问题的。还有以后这种问题最好把你跟踪的代码贴出来。
我估计问题在  protected void DataList1_UpdateCommand(object source, DataListCommandEventArgs e)
= ((TextBox)e.Item.FindControl("txtName")).Text.Trim();这个是不是有问题,能直接找到这个吗?
所以,建议楼主,在这个地方考虑问题。
2010-08-24 22:53
Issac_abc
Rank: 4
来 自:河南
等 级:业余侠客
威 望:2
帖 子:155
专家分:218
注 册:2010-6-17
得分:0 
谢谢:大家我知道那里错了,已经解决了。
2010-08-25 09:57



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-316645-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.151824 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved