更新面板的GridView

更新面板的GridView

本文介绍了更新面板的GridView asp.net C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以帮助我。当我点击ID 1,2 ....采取从查询字符串ID和显示那些名字从哪里查询字符串id是在另一个表id_proba相等。这是确定的,并告诉我。现在我想,当我的ID 1,2点击。在GridView1仅刷新gridview的2并非所有的页面。需要的GridView把阿贾克斯更新面板英寸我把gridview2在更新面板,但不知道做什么,在code写的?

 < ASP:GridView控件ID =GridView1=服务器的AutoGenerateColumns =FALSE
    的DataKeyNames =ID的DataSourceID =SqlDataSource1的cellpadding =4
    前景色=#333333网格=无
    onselectedindexchanged =GridView1_SelectedIndexChanged>
    < AlternatingRowStyle背景色=白/>
    <柱体和GT;
        < ASP:CommandField中ShowSelectButton =真/>
        < ASP:BoundField的数据字段=名称的HeaderText =名SORTEX pression =名/>        < ASP:HyperLinkField字段
  DataTextField =ID
  DataTextFormatString ={0}
  DataNavigateUrlFields =ID的HeaderText =ID
  DataNavigateUrlFormatString =WebForm1.aspx的ID = {0}?/>
    < /专栏>
    < EditRowStyle背景色=#2461BF/>
    < FooterStyle背景色=#507CD1FONT-粗体=真前景色=白/>
    < HeaderStyle背景色=#507CD1FONT-粗体=真前景色=白/>
    < PagerStyle背景色=#2461BF前景色=白Horizo​​ntalAlign =中心/>
    < RowStyle的BackColor =#EFF3FB/>
    < SelectedRowStyle背景色=#D1DDF1FONT-粗体=真前景色=#333333/>
    < SortedAscendingCellStyle背景色=#F5F7FB/>
    < SortedAscendingHeaderStyle背景色=#6D95E1/>
    < SortedDescendingCellStyle背景色=#E9EBEF/>
    < SortedDescendingHeaderStyle背景色=#4870BE/>
< / ASP:GridView的>
< ASP:SqlDataSource的ID =SqlDataSource1=服务器
    的ConnectionString =下;%$的ConnectionStrings:ProbaConnectionString%>中
    DeleteCommand会=删除[Proba1] WHERE [ID] = @id
    将InsertCommand =INSERT INTO [Proba1]([名])VALUES(@name)
    的SelectCommand =SELECT [名],[ID] FROM [Proba1]
    更新命令=UPDATE [Proba1]中的[名] = @name WHERE [ID] = @id>
    < D​​eleteParameters>
        < ASP:参数名称=ID类型=的Int32/>
    < / DeleteParameters>
    < InsertParameters>
        < ASP:参数名称=名字类型=字符串/>
    < / InsertParameters>
    < UpdateParameters>
        < ASP:参数名称=名字类型=字符串/>
        < ASP:参数名称=ID类型=的Int32/>
    < / UpdateParameters>
< / ASP:SqlDataSource的>
< BR />
< ASP:的UpdatePanel ID =UpdatePanel1=服务器>
    <&的ContentTemplate GT;
        < ASP:GridView控件ID =GridView2=服务器的AutoGenerateColumns =FALSE
            的DataSourceID =SqlDataSource2>
            <柱体和GT;
                < ASP:BoundField的数据字段=id_proba的HeaderText =id_proba
                    SORTEX pression =id_proba/>
                < ASP:BoundField的数据字段=名称的HeaderText =名SORTEX pression =名/>
            < /专栏>
        < / ASP:GridView的>
        < ASP:的ScriptManager ID =ScriptManager1=服务器>
        < / ASP:ScriptManager的>
        < ASP:SqlDataSource的ID =SqlDataSource2=服务器
            的ConnectionString =下;%$的ConnectionStrings:ProbaConnectionString%>中
            的SelectCommand =SELECT [id_proba],[名] FROM [proba3] WHERE([id_proba] = @id_proba)>
            < SelectParameters>
                < ASP:QueryStringParameter NAME =id_probaQueryStringField =ID类型=的Int32/>
            < / SelectParameters>
        < / ASP:SqlDataSource的>
    < /&的ContentTemplate GT;
< / ASP:的UpdatePanel>


解决方案

要在 GridView1 点击刷新更新面板,你可以一个javascript onclick处理程序添加到链接 GirdView1 。结果
在这个事件处理程序,你可以通过调用 __ doPostBack 刷新更新面板。你可以使用jQuery的事件处理程序添加到网格中的所有下的标签如下:

 <脚本>
   $(函数(){
         $(#<%= GridView1.ClientID%>将)。绑定(点击,函数(){
             refreshUpdatePanel();
          });
   });  功能refreshUpdatePanel()
  {
    __doPostBack('UpdatePanel1','');
  }
< / SCRIPT>

Can you help me with this. When I click on ID 1,2.... take the ID from query string and display those names where id from query string is equal on id_proba in the other table. This is ok and show me. Now i like when i click on ID 1,2.. in GridView1 to refresh only gridview 2 not all page. Need gridview to put in Ajax Update Panel. I put gridview2 in Update panel but don't know what to write in code?

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
    DataKeyNames="id" DataSourceID="SqlDataSource1" CellPadding="4"
    ForeColor="#333333" GridLines="None"
    onselectedindexchanged="GridView1_SelectedIndexChanged">
    <AlternatingRowStyle BackColor="White" />
    <Columns>
        <asp:CommandField ShowSelectButton="True" />
        <asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />

        <asp:HyperLinkField
  DataTextField="id"
  DataTextFormatString=" {0}"
  DataNavigateUrlFields="id" HeaderText="id"
  DataNavigateUrlFormatString="WebForm1.aspx?ID={0}"   />
    </Columns>
    <EditRowStyle BackColor="#2461BF" />
    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
    <RowStyle BackColor="#EFF3FB" />
    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
    <SortedAscendingCellStyle BackColor="#F5F7FB" />
    <SortedAscendingHeaderStyle BackColor="#6D95E1" />
    <SortedDescendingCellStyle BackColor="#E9EBEF" />
    <SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$ ConnectionStrings:ProbaConnectionString %>"
    DeleteCommand="DELETE FROM [Proba1] WHERE [id] = @id"
    InsertCommand="INSERT INTO [Proba1] ([name]) VALUES (@name)"
    SelectCommand="SELECT [name], [id] FROM [Proba1]"
    UpdateCommand="UPDATE [Proba1] SET [name] = @name WHERE [id] = @id">
    <DeleteParameters>
        <asp:Parameter Name="id" Type="Int32" />
    </DeleteParameters>
    <InsertParameters>
        <asp:Parameter Name="name" Type="String" />
    </InsertParameters>
    <UpdateParameters>
        <asp:Parameter Name="name" Type="String" />
        <asp:Parameter Name="id" Type="Int32" />
    </UpdateParameters>
</asp:SqlDataSource>
<br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
            DataSourceID="SqlDataSource2">
            <Columns>
                <asp:BoundField DataField="id_proba" HeaderText="id_proba"
                    SortExpression="id_proba" />
                <asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
            </Columns>
        </asp:GridView>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:SqlDataSource ID="SqlDataSource2" runat="server"
            ConnectionString="<%$ ConnectionStrings:ProbaConnectionString %>"
            SelectCommand="SELECT [id_proba], [name] FROM [proba3] WHERE ([id_proba] = @id_proba)">
            <SelectParameters>
                <asp:QueryStringParameter Name="id_proba" QueryStringField="ID" Type="Int32" />
            </SelectParameters>
        </asp:SqlDataSource>
    </ContentTemplate>
</asp:UpdatePanel>
解决方案

To refresh the update panel by clicking in GridView1 you could add a javascript onclick handler to the links in GirdView1.
In this event handler you could refresh the update panel by calling __doPostBack. You could use jQuery to add the eventhandler to all a tags in the grid as follows:

<script>
   $(function() {
         $("#<%=GridView1.ClientID%> a").bind('click', function() {
             refreshUpdatePanel();
          });
   });

  function refreshUpdatePanel()
  {
    __doPostBack('UpdatePanel1', '');
  }
</script>

这篇关于更新面板的GridView asp.net C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 23:38