日期:2014-05-17  浏览次数:20531 次

gridview中dropdownlist的赋值问题
我在gridview中的模板列放了个dropdownlist 现在想从数据库读出数据 其中一个属性值要赋值给dropdownlist 并且实现在gridview的updating时 dropdownlist 是激活的 不更新时是不激活的 求大神指导
updating事件
protected void GrvRepairMailbox_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            //this.GrvRepairMailbox.Rows[e.RowIndex].Cells[7].Controls[0]
            string ID = GrvRepairMailbox.DataKeys[e.RowIndex].Value.ToString();
            //string IsVisted = ((TextBox)(GrvRepairMailbox.Rows[e.RowIndex].Cells[5].Controls[0])).Text.ToString().Trim();

            string IsVisted = ((DropDownList)(this.GrvRepairMailbox.Rows[e.RowIndex].FindControl("ddl1"))).SelectedValue.ToString().Trim();

            string Isolved = ((TextBox)(GrvRepairMailbox.Rows[e.RowIndex].Cells[6].Controls[0])).Text.ToString().Trim();
            string udpsql = "update EP_TblMailbox set IsVisted='" + IsVisted + "', Isolved='" + Isolved + "' where ID='" + ID + "'";
            dataOperate.execSQL(udpsql);
            GrvRepairMailbox.EditIndex = -1;
            GrvRepairMailboxbindData();
        }

绑定数据
protected void GrvRepairMailboxbindData()
        {
            string sql = "select * from EP_TblMailbox where SendToDepartment = '维修部'";
            GrvRepairMailbox.DataSource = dataOperate.getDataset(sql, "EP_TblRepairMailbox");
            GrvRepairMailbox.DataKeyNames = new string[] { "ID" };
            GrvRepairMailbox.DataBind();
}

前台代码
<asp:GridView ID="GrvRepairMailbox" runat="server" AutoGenerateColumns="False" 
            onselectedindexchanging="GrvRepairMailbox_SelectedIndexChanging" 
            onrowcancelingedit="GrvRepairMailbox_RowCancelingEdit" 
            onrowediting="GrvRepairMailbox_RowEditing" 
            onrowupdating="GrvRepairMailbox_RowUpdating">
            <Columns>
                <asp:BoundField DataField="ID" HeaderText="编号" />
                <asp:BoundField DataField="SenderName" HeaderText="发布人" /&g