部分代码如下:        
<asp:UpdatePanel ID="UpdatePanel4" runat="server"  >
      <ContentTemplate><asp:GridView ID="GridViewOtherDevice" runat="server"  CssClass="Grid_01" 
                BackColor="#F6F6F6" Width="780px" AutoGenerateColumns="False"   
                  OnRowCommand="GridViewOtherDevice_RowCommand" AllowSorting=True >
            <Columns>
                <asp:TemplateField ShowHeader="False">
                    <ItemTemplate>
                        <asp:LinkButton ID="LinkButtonOtherDevice" runat="server" CausesValidation="False"  CommandArgument='<%# Eval("ID")%>' 
                            CommandName="Agree" Text="批准"></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>                <asp:BoundField DataField="ID"  HeaderText="编号" />                <asp:TemplateField  SortExpression="State" ItemStyle-Width="50px">
                    <HeaderTemplate>
                        状态
                        <asp:DropDownList ID="DDLState" runat="server" AutoPostBack=true OnSelectedIndexChanged="DDL_SelectChanged" >
                            <asp:ListItem Value="所有">所有</asp:ListItem>
                            <asp:ListItem Value="还">还</asp:ListItem>
                            <asp:ListItem Value="催还">催还</asp:ListItem>
                        </asp:DropDownList>
                    </HeaderTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("State") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="Type"  HeaderText="设备类型" />
 
                <asp:BoundField DataField="Res"  HeaderText="备注" />
            </Columns>
        </asp:GridView>
                     
        </ContentTemplate>
</asp:UpdatePanel>
出现的问题:我选择DropDownList 的某个选项(如"催还")后,触发DDL_SelectChanged,页面返回更新的GridView信息,但是同时DropDownList中的选项又变成初始选项(所有"),怎么样让DropDownList的选项不还原为初始
问题补充:如果DropDownList如果不在GridView内部,就不会还原为初始选项。
各位前辈帮忙看看。谢谢啦

解决方案 »

  1.   

    选择的绑定的时候记录Dropdownlist的selectindex绑定完毕后 指定Dropdownlist 的selectindex.
      

  2.   

    我试过了后台中,在DropDownlist本身的DDL_SelectChanged里给它指定初始值,这样反而照成没有筛选的效果补充:这里GridView中的DropDownlist相当于自制的表头筛选器
      

  3.   

    绑定数据源的时候
    if(!isPostPack)
    {
    Gridview1.datasource=数据源;
    GrideView1.databind();
    }
      

  4.   

    asp:UpdatePanel 
    拖一个无刷新控件上去
      

  5.   


    整个GridView已经在asp:UpdatePanel里了
      

  6.   


    后台代码。我把DDL_SelectChanged的贴出来,其它的不相关的很长。
        protected void DDL_SelectChanged(Object sender, EventArgs e)
        {
            DropDownList DDL = sender as DropDownList;
            string ParName = DDL.ID;
            string ParSqlName = DDL.ID.Remove(0, 3);
            string PartSelectCommand = "(" + ParSqlName + "=@" + ParName + ") AND ";
            string ParValue= DDL.SelectedValue;
            if (SqlDataSourceOtherDevice.SelectParameters[ParName] != null)
            {
                SqlDataSourceOtherDevice.SelectParameters.Remove(SqlDataSourceOtherDevice.SelectParameters[ParName]);
            }
            if (ParValue == "所有")
            {
                SqlDataSourceOtherDevice.SelectCommand = SqlDataSourceOtherDevice.SelectCommand.Replace(PartSelectCommand, " ");
            }
            else
            {
                SqlDataSourceOtherDevice.SelectParameters.Add(ParName, ParValue);
                if (!SqlDataSourceOtherDevice.SelectCommand.Contains(PartSelectCommand))
                {
                    SqlDataSourceOtherDevice.SelectCommand = SqlDataSourceOtherDevice.SelectCommand.Replace("WHERE ","WHERE "+PartSelectCommand);
                }
            }
            GridViewOtherDevice.DataBind();        
        }
      

  7.   

    怎么用啊异步方式,我不会。 我这GridView里只要表头不更新
      

  8.   

    本人试出了一个比较别扭的方法。
    把DropDownList放在Gridview外头隐藏起来,GridView里用一个select代替它,然后用编码把两者联动起来.aspx文件相关代码:
            <div class="DisplayNone">
                                                     <asp:DropDownList ID="DDLState" runat="server" AutoPostBack=true OnSelectedIndexChanged="DDL_SelectChanged"  >
                                <asp:ListItem Value="所有"  >所有</asp:ListItem>
                                <asp:ListItem Value="还" >还</asp:ListItem>
                                <asp:ListItem Value="催还" >催还</asp:ListItem>
                            </asp:DropDownList></div>

    <asp:UpdatePanel ID="UpdatePanel4" runat="server" >
      <ContentTemplate><asp:GridView ID="GridViewOtherDevice" runat="server" CssClass="Grid_01"  
      BackColor="#F6F6F6" Width="780px" AutoGenerateColumns="False"   
      OnRowCommand="GridViewOtherDevice_RowCommand" AllowSorting=True >
      <Columns>
      <asp:TemplateField ShowHeader="False">
      <ItemTemplate>
      <asp:LinkButton ID="LinkButtonOtherDevice" runat="server" CausesValidation="False" CommandArgument='<%# Eval("ID")%>'  
      CommandName="Agree" Text="批准"></asp:LinkButton>
      </ItemTemplate>
      </asp:TemplateField>  <asp:BoundField DataField="ID" HeaderText="编号" />  <asp:TemplateField SortExpression="State" ItemStyle-Width="50px">
      <HeaderTemplate>
      状态
                            <select id="SelectState"  onchange="StateChange()"   />
                                    <option value="所有"  <% =(test("ctl00$CPHBody$DDLState")=="所有"?"selected=selected ":"") %> >所有</option>
                                    <option value="还"  <% =(test("ctl00$CPHBody$DDLState")=="还"?"selected=selected ":"") %>  >还</option>
                                    <option value="催还"  <% =(test("ctl00$CPHBody$DDLState")=="催还"?"selected=selected ":"") %> >催还</option>
                                </select>

      </HeaderTemplate>
      <ItemTemplate>
      <asp:Label ID="Label1" runat="server" Text='<%# Bind("State") %>'></asp:Label>
      </ItemTemplate>
      </asp:TemplateField>
      <asp:BoundField DataField="Type" HeaderText="设备类型" />
      
      <asp:BoundField DataField="Res" HeaderText="备注" />
      </Columns>
      </asp:GridView>
        
      </ContentTemplate>
    </asp:UpdatePanel>
    JS文件相关代码:
    function StateChange()
    {
        document.getElementById("ctl00_CPHBody_DDLState").value=document.getElementById("SelectState").value
        __doPostBack("ctl00$CPHBody$DDLState","");
    }.cs文件相关代码
        protected void DDL_SelectChanged(Object sender, EventArgs e)
        {
            DropDownList DDL = sender as DropDownList;
            string ParName = DDL.ID;
            string ParSqlName = DDL.ID.Remove(0, 3);
            string PartSelectCommand = "(" + ParSqlName + "=@" + ParName + ") AND ";
            string ParValue= DDL.SelectedValue;
            if (SqlDataSourceOtherDevice.SelectParameters[ParName] != null)
            {
                SqlDataSourceOtherDevice.SelectParameters.Remove(SqlDataSourceOtherDevice.SelectParameters[ParName]);
            }
            if (ParValue == "所有")
            {
                SqlDataSourceOtherDevice.SelectCommand = SqlDataSourceOtherDevice.SelectCommand.Replace(PartSelectCommand, " ");
            }
            else
            {
                SqlDataSourceOtherDevice.SelectParameters.Add(ParName, ParValue);
                if (!SqlDataSourceOtherDevice.SelectCommand.Contains(PartSelectCommand))
                {
                    SqlDataSourceOtherDevice.SelectCommand = SqlDataSourceOtherDevice.SelectCommand.Replace("WHERE ","WHERE "+PartSelectCommand);
                }
            }
            GridViewOtherDevice.DataBind();  
        }    public string test(string Conid)
        {
            DropDownList theDDL = FindControl(Conid) as DropDownList;
                    return theDDL.SelectedValue;
        }