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

点击GridView中的选择按钮时,DetailsView控件中不能显示相应行的数据?解决思路

2012-01-03 
点击GridView中的选择按钮时,DetailsView控件中不能显示相应行的数据?点击GridView中的选择按钮时,Details

点击GridView中的选择按钮时,DetailsView控件中不能显示相应行的数据?
点击GridView中的选择按钮时,DetailsView控件中不能显示相应行的数据.请问是什么原因?   谢谢!

代码如下:

<asp:Content   ID= "Content1 "   ContentPlaceHolderID= "ContentPlaceHolder1 "   Runat= "Server ">
        <span   style= "font-family:   仿宋_GB2312;   text-decoration:   underline "> <strong> 工程设置 <br   />
               
        </strong> </span> &nbsp; <br   />
        <asp:AccessDataSource   ID= "AccessDataSource1 "   runat= "server "   DataFile= "~/newsdb.mdb "
                SelectCommand= "SELECT   [Id],   [Projectname],   [Remark]   FROM   [project] "   >
            </asp:AccessDataSource>
       
          <asp:AccessDataSource   ID= "AccessDataSource2 "   runat= "server "   DataFile= "~/newsdb.mdb "
                SelectCommand= "SELECT   [Id],   [Projectname],   [Remark]   FROM   [project] "     FilterExpression= "id= '@id ' "     >
                    <FilterParameters>
                    <asp:ControlParameter   Name= "id "   ControlID= "gridview1 "   PropertyName= "selectedvalue "   />
                </FilterParameters>
        </asp:AccessDataSource>
       
        <asp:GridView   ID= "GridView1 "   runat= "server "   DataKeyNames= "Id "   DataMember= "DefaultView "          
        DataSourceID= "AccessDataSource1 "   CellPadding= "4 "   ForeColor= "#333333 "       GridLines= "None "   PageSize= "20 "   AutoGenerateColumns= "False "  
        >
                <Columns>
                        <asp:BoundField   DataField= "Id "   HeaderText= "序号 "   ReadOnly= "True "   SortExpression= "Id "   />
                        <asp:BoundField   DataField= "Projectname "   HeaderText= "工程名称 "   SortExpression= "Projectname "   />
                        <asp:BoundField   DataField= "Remark "   HeaderText= "备注 "   SortExpression= "Remark "   />
                        <asp:CommandField   ShowEditButton= "True "   ButtonType= "Button "   >
                        <HeaderStyle   Width= "80px "   />
                        </asp:CommandField>


                        <asp:CommandField   ShowDeleteButton= "True "   ButtonType= "Button "   >
                        <HeaderStyle   Width= "40px "   />
                        </asp:CommandField>
                        <asp:CommandField   ShowSelectButton= "True "   SortExpression= "Id "   />
                </Columns>
                <FooterStyle   BackColor= "#507CD1 "   Font-Bold= "True "   ForeColor= "White "   />
                <RowStyle   BackColor= "#EFF3FB "   />
                <EditRowStyle   BackColor= "#2461BF "   />
                <SelectedRowStyle   BackColor= "#D1DDF1 "   Font-Bold= "True "   ForeColor= "#333333 "   />
                <PagerStyle   BackColor= "#2461BF "   ForeColor= "White "   HorizontalAlign= "Center "   />
                <HeaderStyle   BackColor= "#507CD1 "   Font-Bold= "True "   ForeColor= "White "   />
                <AlternatingRowStyle   BackColor= "White "   />
        </asp:GridView>
        <br   />
        <asp:DetailsView   ID= "DetailsView1 "   runat= "server "   AutoGenerateRows= "False "
                        DataKeyNames= "Id "   DataMember= "DefaultView "   DataSourceID= "AccessDataSource2 "   EnablePagingCallbacks= "True "   >
                        <Fields>
                                <asp:BoundField   DataField= "Id "   HeaderText= "Id "   ReadOnly= "True "   SortExpression= "Id "   />
                                <asp:BoundField   DataField= "Projectname "   HeaderText= "Projectname "   SortExpression= "Projectname "   />
                                <asp:BoundField   DataField= "Remark "   HeaderText= "Remark "   SortExpression= "Remark "   />
                        </Fields>
                </asp:DetailsView>
</asp:Content>


[解决办法]


如果共用一个DataSource那就不用写代码,否则就需要在GridView的SelectedIndexChanged根据选中的行的关键字来更新DetailsView

热点排行