Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Gridview中的编辑按钮不工作_C#_Asp.net_Gridview - Fatal编程技术网

C# Gridview中的编辑按钮不工作

C# Gridview中的编辑按钮不工作,c#,asp.net,gridview,C#,Asp.net,Gridview,我试图使用网格视图来显示多个表(EMPDail、Department、Country、State、City、Qualification)的联接。主表(Empdetail)具有不同的ID(例如DeptID),它们引用表中存在的主键ID。我希望部门(和其他字段)在更新gridview时显示为下拉选项,但在填充下拉列表并启动编辑按钮时,我面临问题。下面是代码 .ASPX 员工数据库 //创建加载效果的步骤 功能块UI(elementID){ var prm=Sys.WebForms.PageReq

我试图使用网格视图来显示多个表(EMPDail、Department、Country、State、City、Qualification)的联接。主表(Empdetail)具有不同的ID(例如DeptID),它们引用表中存在的主键ID。我希望部门(和其他字段)在更新gridview时显示为下拉选项,但在填充下拉列表并启动编辑按钮时,我面临问题。下面是代码

.ASPX


员工数据库
//创建加载效果的步骤
功能块UI(elementID){
var prm=Sys.WebForms.PageRequestManager.getInstance();
prm.add_beginRequest(函数(){
$(“#”+elementID).block({消息:“”+
'',
css:{},
覆盖层:{背景颜色:'#000000',不透明度:0.6,边框:'3px实心#63B2EB'
}
});
});
prm.add_endRequest(函数(){
$(“#”+elementID).unblock();
});
}
$(文档).ready(函数(){
BlockUI(“dvGrid”);
$.blockUI.defaults.css={};
});

在aspx文件中,我会删除每个下拉列表的数据源,例如SqlDataSource。在标记中,您可以完全定义每个DDL,并且每行使用数据源的同一个实例。编辑时,只需捕获要更新的选定值

所以…部门示例的数据源

    . . .
    </asp:GridView>

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:SQLDbConnection %>"
        SelectCommand="SELECT ID,DeptName FROM Department"
        EnableCaching="True">
    </asp:SqlDataSource>

在注释了几段代码后,我意识到问题出在“OnRowDataBound”函数上。 注释这些行使更新按钮再次启动:-

stringdepartment=(e.Row.FindControl(“lblDepartment”)作为标签);

depdll.Items.FindByValue(Department).Selected=true谢谢。我没有意识到这样的控制。嗨,你实现了选择价值问题吗?
    <EditItemTemplate>
        <asp:DropDownList ID = "Depddl" runat="server" Width="100px" >
            DataSourceID="SqlDataSource1"                               
            DataTextField="DeptName" 
            DataValueField="ID"
        </asp:DropDownList>
    </EditItemTemplate>
protected void GridView1_RowDataBound( object sender, GridViewRowEventArgs e )
{
    if ( e.Row.RowType == DataControlRowType.DataRow )
    {
        if ( e.Row.RowState.HasFlag( DataControlRowState.Edit ) )
        {
            DataRowView drv = (DataRowView) e.Row.DataItem;
            DropDownList ddl = (DropDownList) e.Row.FindControl( "DropDownList1" );
            ddl.SelectedValue = ((int) drv[ "ID" ]).ToString();
        }
    }
}