Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/272.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# DropDownList无法在GridViewSelectedIndexChangedEvent上设置DataTextField_C#_Asp.net - Fatal编程技术网

C# DropDownList无法在GridViewSelectedIndexChangedEvent上设置DataTextField

C# DropDownList无法在GridViewSelectedIndexChangedEvent上设置DataTextField,c#,asp.net,C#,Asp.net,我有一个名称表格: 创建表TblDesignation ( [DesgId][int]标识(1,1)不为空, [名称][nvarchar](50)不为空, 约束[PK_TblDesignation]主键群集 ( [DesgId]ASC )在[主]上打开(PAD\u INDEX=OFF,STATISTICS\u norecocomputer=OFF,IGNORE\u DUP\u KEY=OFF,ALLOW\u ROW\u LOCKS=ON,ALLOW\u PAGE\u LOCKS=ON) )在[小

我有一个
名称
表格:

创建表TblDesignation
(
[DesgId][int]标识(1,1)不为空,
[名称][nvarchar](50)不为空,
约束[PK_TblDesignation]主键群集
(
[DesgId]ASC
)在[主]上打开(PAD\u INDEX=OFF,STATISTICS\u norecocomputer=OFF,IGNORE\u DUP\u KEY=OFF,ALLOW\u ROW\u LOCKS=ON,ALLOW\u PAGE\u LOCKS=ON)
)在[小学]
Employee.aspx页面代码:

 <div id="divView" align="center" runat="server" >
    <asp:Panel ID="Panel1" runat="server">
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            CellPadding="4" ForeColor="#333333" GridLines="None" 
            DataSourceID="SqlDataSource1" 
            onselectedindexchanged="GridView1_SelectedIndexChanged">
            <AlternatingRowStyle BackColor="White" />
            <Columns>
                <asp:CommandField ShowSelectButton="True" />
                <asp:BoundField DataField="EmpId" HeaderText="EMP ID" />
                <asp:BoundField DataField="EmpFirstName" HeaderText="FIRST NAME" />
                <asp:BoundField DataField="EmpMiddleName" HeaderText="MIDDLE NAME" />
                <asp:BoundField DataField="EmpLastName" HeaderText="LAST NAME" />
                <asp:BoundField DataField="EmpGender" HeaderText="GENDER" />
                <asp:BoundField DataField="EmpDesignation" HeaderText="DESIGNATION" />
                <asp:BoundField DataField="EmpAddress" HeaderText="ADDRESS" />
                <asp:BoundField DataField="EmpEmailId" HeaderText="EMAIL ID" />
                <asp:BoundField DataField="EmpContactNo" HeaderText="CONTACT" />
                <asp:BoundField DataField="EmpDOB" HeaderText="D.O.B" dataformatstring="{0:MM/dd/yyyy}"/>
            </Columns>
            <EditRowStyle BackColor="#7C6F57" />
            <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
            <RowStyle BackColor="#E3EAEB" />
            <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
            <SortedAscendingCellStyle BackColor="#F8FAFA" />
            <SortedAscendingHeaderStyle BackColor="#246B61" />
            <SortedDescendingCellStyle BackColor="#D4DFE1" />
            <SortedDescendingHeaderStyle BackColor="#15524A" />
        </asp:GridView>

        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:MSAMBConnectionString %>" 
            SelectCommand="SELECT * FROM [TblEmployee]"></asp:SqlDataSource>

    </asp:Panel>
    <asp:Button ID="btnAddNew" runat="server" Text="ADD NEW EMPLOYEE" 
        onclick="btnAddNew_Click" />
</div>
<div id="divForm" runat="server"  style="margin-top:4%;">
<table border="2" align="center">
<tr>
<td>
    <asp:Label ID="LblEmpId" runat="server" Text="EMP ID"></asp:Label>
</td>
<td>
    <asp:TextBox ID="txtEmpId" runat="server" Enabled="False"></asp:TextBox>
</td>
</tr>
<tr>
<td>
    <asp:Label ID="LblEmpFirstName" runat="server" Text="FIRST NAME : "></asp:Label>
</td>
<td>
    <asp:TextBox ID="txtEmpFirstName" runat="server"></asp:TextBox>
</td>
</tr>

<tr>
<td>
    <asp:Label ID="LblEmpMiddleName" runat="server" Text="MIDDLE NAME : "></asp:Label>
</td>
<td>
    <asp:TextBox ID="txtEmpMiddleName" runat="server"></asp:TextBox>
</td>
</tr>

<tr>
<td>
    <asp:Label ID="LblEmpLastName" runat="server" Text="LAST NAME : "></asp:Label>
</td>
<td>
    <asp:TextBox ID="txtEmpLastName" runat="server"></asp:TextBox>
</td>
</tr>

<tr>
<td>
    <asp:Label ID="LblGender" runat="server" Text="GENDER : "></asp:Label>
</td>
<td>
    <asp:RadioButton ID="rbMale" runat="server" Text="Male" GroupName="Gender" />
    <asp:RadioButton ID="rbFemale" runat="server" Text="Female" GroupName="Gender" />
</td>
</tr>


<tr>
<td>
    <asp:Label ID="LblEmpDesignation" runat="server" Text="DESIGNATION : "></asp:Label>
</td>
<td>
    <asp:DropDownList ID="ddrDesgn" runat="server" DataSourceID="SqlDataSource2" 
        DataTextField="Designation" DataValueField="DesgId" 
        onselectedindexchanged="ddrDesgn_SelectedIndexChanged" AutoPostBack="True">
    </asp:DropDownList>

    **<asp:SqlDataSource ID="SqlDataSource2" runat="server" 
         ConnectionString="<%$ ConnectionStrings:MSAMBConnectionString3 %>
     SelectCommand="SELECT * FROM [TblDesignation]"></asp:SqlDataSource>**

</td>
</tr>



<tr>
<td>
    <asp:Label ID="LblEmpAddress" runat="server" Text="ADDRESS : "></asp:Label>
</td>
<td>
    <asp:TextBox ID="txtEmpAddress" runat="server"></asp:TextBox>
</td>
</tr>

<tr>
<td>
    <asp:Label ID="LblEmpEmailId" runat="server" Text="EMAIL ID : "></asp:Label>
</td>
<td>
    <asp:TextBox ID="txtEmpEmailId" runat="server"></asp:TextBox>
</td>
</tr>

<tr>
<td>
    <asp:Label ID="LblEmpContactNo" runat="server" Text="CONTACT NO : "></asp:Label>
</td>
<td>
    <asp:TextBox ID="txtEmpContactNo" runat="server"></asp:TextBox>
</td>
</tr>


<tr>
<td>
    <asp:Label ID="LblEmpDOB" runat="server" Text="DOB : "></asp:Label>
</td>
<td>
    <asp:TextBox ID="txtEmpDOB" runat="server"></asp:TextBox>
    <asp:CalendarExtender ID="txtEmpDOB_CalendarExtender" runat="server" 
        Enabled="True" TargetControlID="txtEmpDOB">
    </asp:CalendarExtender>
</td>
</tr>
    <tr>
    <td colspan="1" align="center">
        <asp:Button ID="btnSubmit" runat="server" Text="SAVE" 
            onclick="btnSubmit_Click" /></td>
        <td><asp:Button ID="btnUpdate" runat="server" Text="UPDATE" 
                onclick="btnUpdate_Click" />
    </td>
    </tr>
    <tr>
    <td colspan="2">
    <asp:Label ID="lblMsg" runat="server" Text=""></asp:Label>
    <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Employee.aspx">BACK</asp:HyperLink>
    </td>

    </tr>


</table>

</div>
这给了我一个错误:

DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'MD'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.    
Exception Details: System.Web.HttpException: DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'MD'.
源错误:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

似乎您的网格认为您试图绑定到一个名为“MD”的东西,而源数据中不存在这样的东西,虽然我在您的代码中看不到,但请尝试此操作转到visual studio,Server Exolorer(Ctrl-Alt-S)创建到数据库的连接,导航到表,确保您在ASP页面上处于GUI模式,然后将表拖到页面上,VS将自动生成SQL和Gridview,从那里您应该能够使用数据源或网格添加/删除列,直到您得到所需的内容。

在CS代码中,我有这样的连接字符串。。SqlConnection con=新的SqlConnection(ConfigurationManager.ConnectionString[“con”].ConnectionString);在ASPX页面上,dropdoenlist与如下表绑定…您的问题是我有一个指定表:但您的代码正在gridview中执行DataSourceID=“SqlDataSource1”,您的SQL代码将从Datasource 1中的[TblEmployee]中选择*,在页面的下一步,您有SqlDataSource2,其中包含SELECT*FROM[TbledSignation],我认为您需要更改datasource,将Gridview1的ID属性更改为DataSourceID=“SqlDataSource2”好,但在gridview中,我必须显示来自TblEmployee的所有记录,在dropdownlist中,它显示来自TblDesignation表的指定……dropdownlist需要位于网格中的模板内
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.