首页 新闻 会员 周边 捐助

asp.net gridview绑定了第三方控件ColorPicker一列,但是点击该空间选择颜色赋值时却只能赋值到第一行

0
悬赏园豆:15 [已解决问题] 解决于 2014-02-18 18:02

asp.net gridview绑定了第三方控件ColorPicker一列,但是点击该控件选择颜色赋值时却只能赋值到第一行,除了第一行之外的赋值不上怎么办??

代码如下:

 protected void GridView3_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "ModifyButton")
        {
         
            int i =Convert.ToInt32( e.CommandArgument.ToString());
            System.Web.UI.WebControls.TextBox tb = GridView3.Rows[i].FindControl("tbname") as System.Web.UI.WebControls.TextBox;
            string statusName = tb.Text;
            HiddenField hf = GridView3.Rows[i].FindControl("hiddenColor") as HiddenField;
            HiddenField hf1 = GridView3.Rows[i].FindControl("hiddenId") as HiddenField;
            ColorPicker cp = GridView3.Rows[i].FindControl("ColorPicker2") as ColorPicker;
            string color = cp.Color;
 
            if (statusName != string.Empty &&color!=string.Empty )
            {
                int id = Convert.ToInt32(hf1.Value);
                string sqlupdate = string.Format("update Status set StatusName='{0}',StatusColor='{1}' where ID='{2}'", statusName, color, id);
                int result = SqlHelper.ExecuteNonQuery(connectionString, System.Data.CommandType.Text, sqlupdate);
                if (result > 0)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "提示", "alert('修改成功~!')", true);
                    BindStatus();
                    TabWebControl1.SelectedTabIndex = 3;
                    //Response.Redirect("AdminManager.aspx");
                }
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "提示", "alert('状态名和颜色不能为空~!')", true);
            }
         
        }

lijunmomo的主页 lijunmomo | 初学一级 | 园豆:34
提问于:2014-01-08 15:02
< >
分享
最佳答案
0

你应该用clientID

收获园豆:15
pmghy | 菜鸟二级 |园豆:234 | 2014-01-08 17:38
其他回答(1)
0

我怀疑是你使用了在Grid中使用了客户端ID,同时ColorPicker注册到了ID上。然后GridView渲染数据的时候,ID重复了。这个时候,ColorPicker就只能设置第一个框了。因为ID选择器只匹配第一个。你应该贴前台的GridView代码。

幻天芒 | 园豆:37207 (高人七级) | 2014-01-08 17:29

谢谢你!这是前台代码,你帮我看看,该怎么改,在线等你

<asp:GridView
        ID="GridView3" runat="server" AutoGenerateColumns="False"
                     CellPadding="4" EnableModelValidation="True" ForeColor="#333333"
                     GridLines="None" onrowcommand="GridView3_RowCommand"><AlternatingRowStyle
            BackColor="White" /><Columns><asp:TemplateField HeaderText="状态名"><ItemTemplate><asp:TextBox ID="tbname" runat="server"
                                     Text='<%#Eval("StatusName")%>'></asp:TextBox></ItemTemplate></asp:TemplateField><asp:TemplateField HeaderText="颜色"><ItemTemplate>
                                     <cc2:ColorPicker runat="server" Color='<%#Eval("StatusColor")%>' ID="ColorPicker2"  oncolorchanged="ColorPicker2_ColorChanged" /><asp:HiddenField ID="hiddenColor" runat="server"
                                     Value='<%#Eval("StatusColor")%>' /><asp:HiddenField ID="hiddenId" runat="server" Value='<%#Eval("ID")%>' /></ItemTemplate></asp:TemplateField><asp:TemplateField HeaderText="删除"><ItemTemplate><asp:ImageButton ID="ImageButton1" runat="server"
                                             CommandArgument='<%#DataBinder.Eval(Container,"RowIndex")%>'
                                             CommandName="deleteButton" ImageUrl="~/images/del3.png"></asp:ImageButton></ItemTemplate></asp:TemplateField><asp:TemplateField HeaderText="修改"><ItemTemplate><asp:ImageButton ID="ok" runat="server"
                                     CommandArgument='<%#DataBinder.Eval(Container,"RowIndex")%>'
                                     CommandName="ModifyButton" ImageUrl="~/images/modify.png" /></ItemTemplate></asp:TemplateField></Columns><EditRowStyle BackColor="#2461BF" /><FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /><HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /><PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" /><RowStyle BackColor="#EFF3FB" /><SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" /></asp:GridView>

支持(0) 反对(0) lijunmomo | 园豆:34 (初学一级) | 2014-01-08 17:40

@lijunmomo: 不好意思,不是频繁看博文。看看ColorPicker2_ColorChanged这个方法的实现。

支持(0) 反对(0) 幻天芒 | 园豆:37207 (高人七级) | 2014-01-09 09:49

@幻天芒: 这个事件根本就不触发的。。。不知道怎么回事

支持(0) 反对(0) lijunmomo | 园豆:34 (初学一级) | 2014-01-09 09:55

@lijunmomo:那参考下这个控件的api。 

支持(0) 反对(0) 幻天芒 | 园豆:37207 (高人七级) | 2014-01-09 11:54

@幻天芒: api什么意思呢?

支持(0) 反对(0) lijunmomo | 园豆:34 (初学一级) | 2014-01-09 12:46

@lijunmomo:API(Application Programming Interface,应用程序编程接口)

你就看看这个控件的demo吧。 

支持(0) 反对(0) 幻天芒 | 园豆:37207 (高人七级) | 2014-01-09 13:45
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册