1

我有一个按钮,onClick事件,我想将数据从 Oracle DB 加载GridViewModalPopupExtender.

问题是 Modalpopup 正在显示,但 gridView 中没有数据加载。

谁能指导我在哪里做错了。

ASP 代码

     <asp:Label ID="dummyLabel" runat="server" />
                    <ajax:ModalPopupExtender ID="mpeServiceType" runat="server" TargetControlID="dummyLabel" CancelControlID="BtnCloseServiceTypeMPE" Drag="true" PopupControlID="pnlServiceType" Enabled="True" >
                    </ajax:ModalPopupExtender>
 <asp:Button runat="server" ID="btnSelectServiceType" Text="Select Srv Type" OnClick="btnSelectServiceType_Click" />   
      <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="conditional" ChildrenAsTriggers="true">
                <ContentTemplate>
                    <asp:Button ID="Button2" Style="display: none" runat="server" Width="120" Text="Filter Charges" ToolTip="show Chargefilter-Dialog" />
                    <asp:Button ClientIDMode="Static" ID="BtnCloseServiceTypeMPE" Text="Close" ToolTip="close filter-dialog" CausesValidation="false" Width="150px" runat="server" /><br />
                    <table border="1">
                        <tr>
                            <td dir="rtl">
                                 <asp:GridView ID="gvServiceType" runat="server" 

CssClass="mGrid" AlternatingRowStyle-CssClass="alt" DataKeyNames="APP_ID,SRV_TYPE"

 AutoGenerateColumns="False" OnSelectedIndexChanged="gvServiceType_SelectedIndexChanged">
                                      <Columns>
                                        <asp:BoundField DataField="APP_ID" HeaderText=(APP_ID)" ReadOnly="True" SortExpression="APP_ID" />
                                        <asp:BoundField DataField="SRV_TYPE" HeaderText="SRV_TYPE)" SortExpression="SRV_TYPE" ReadOnly="True" />
                                        <asp:BoundField DataField="SRV_NAME" HeaderText="SRV_NAME)" SortExpression="SRV_NAME" />
                                        <asp:TemplateField HeaderText="Select">
                                            <ItemTemplate>
                                                <asp:Button ID="btnSelect" runat="server" CommandName="Select" Text="Select" />
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                    </Columns>
                                      </asp:GridView>
                                </td>
                            </tr>
                        </table>
                    </ContentTemplate>
                </asp:UpdatePanel>

C# 代码

 protected void btnSelectServiceType_Click(object sender, EventArgs e)
        {
            string strSQLconnection = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.0.0.24)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=PROD)));User Id=aaziz;Password=32145;";
            OracleConnection conn = new OracleConnection(strSQLconnection);
            OracleCommand sqlCommand = new OracleCommand("select * from INCOME.srv_types where APP_ID='3' AND SRV_TYPE='8'", conn);
            conn.Open();
            OracleDataReader reader = sqlCommand.ExecuteReader();
            gvServiceType.DataSource = reader;
            gvServiceType.DataBind();
            mpeServiceType.Show();
}
4

1 回答 1

0

我没有使用 Oracle 的经验,但是当我使用阅读器从 SQL Server 调用数据时,我通常必须在将其用作数据源之前绑定列表。

例如

OracleDataReader reader = sqlCommand.ExecuteReader();
List<YourClass> list= new List<YourClass>();
while(reader.Read())
{
    YourClass yourClass = new YourClass
    {
        APP_ID=Convert.ToInt32(reader["APP_ID"]);
        //and so on with all the other properties you need.
    }
    list.Add(yourClass);
}

gvServiceType.DataSource = list;
gvServiceType.DataBind();
于 2013-11-04T12:52:07.987 回答