首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

gridview中dropdownlist的赋值有关问题

2013-04-26 
gridview中dropdownlist的赋值问题我在gridview中的模板列放了个dropdownlist 现在想从数据库读出数据 其

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="发布人" />
                <asp:BoundField DataField="SendDepartment" HeaderText="发布部门" />


                <asp:BoundField DataField="ReportID" HeaderText="报告编号" />
                <asp:BoundField DataField="Type" HeaderText="报告类型" />
                <asp:BoundField DataField="IsVisted" HeaderText="已阅读" />
                <asp:BoundField DataField="Isolved" HeaderText="已解决" />
                <asp:TemplateField HeaderText="是否阅读">
                    <ItemTemplate>
                        <asp:DropDownList ID="ddl1" runat="server" AutoPostBack="True">
                            <asp:ListItem Value="true">是</asp:ListItem>
                            <asp:ListItem Value="false">否</asp:ListItem>
                        </asp:DropDownList>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:CommandField ShowSelectButton="True" />
                <asp:CommandField ShowEditButton="True" />
            </Columns>
        </asp:GridView>


求大神指导 我搜索了好多的资料还是没有比较好的解释 求大神写个例子
[解决办法]
try:
http://www.cnblogs.com/insus/articles/1411016.html#2053183

热点排行