简体   繁体   English

更新面板无法正常工作

[英]Update panel not working correctly

I wrapped my Gridview inside Update panel and set trigger to search button but it doesn't work correctly, When i put text into textbox and click search then gridview display relevant results, that's ok but it should load column's text into Textbox upon clicking Gridview's SELECT button which was working before putting Update panel but not now. 我将Gridview包裹在“更新”面板中,并将触发器设置为“搜索”按钮,但无法正常工作,当我将文本放入文本框并单击“搜索”,然后Gridview显示相关结果时,可以,但是单击Gridview的SELECT时应将列的文本加载到“文本框”中按钮,该按钮在放置“更新”面板之前有效,但现在不起作用。 Neither it loads text into textbox and nor does it load again after clicking Search button. 单击“搜索”按钮后,既不会将文本加载到文本框中,也不会再次加载文本。

CODE: 码:

<asp:UpdatePanel ID="UpdatePanel2" runat="server">
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="btnSearch" EventName="Click" />
                </Triggers>
                <ContentTemplate>
                    <asp:GridView ID="gridViewComplaints" AutoGenerateSelectButton="true" runat="server" CssClass="mGrid" OnSelectedIndexChanged="gridViewComplaints_SelectedIndexChanged">
              <EmptyDataRowStyle BorderStyle="None" ForeColor="Red" BorderWidth="0px" />
               <EmptyDataTemplate>
                  No Data Found for this Input. Try Again.
               </EmptyDataTemplate> 
             <SelectedRowStyle CssClass="selected-row" BackColor="YellowGreen" ForeColor="white" />
             </asp:GridView>
                </ContentTemplate>
            </asp:UpdatePanel>

 protected void gridViewComplaints_SelectedIndexChanged(object sender, EventArgs e)
    {
        GridViewRow row = gridViewComplaints.SelectedRow;
        txtComplaintSubject.Text = row.Cells[2].Text;
        HiddenFieldComplaintID.Value = row.Cells[1].Text;
        int cid = Convert.ToInt32(HiddenFieldComplaintID.Value);
        Response.Write(cid.ToString());
        gridViewComplaints.Visible = false;

    }

This is how it works for me. 这就是我的工作方式。 If you can try this code : 如果可以尝试以下代码:

<asp:UpdatePanel ID="UpdatePanel2" runat="server">
    <ContentTemplate>
        <asp:GridView ID="GridView1" class="gridview" OnRowCommand="EditGridData" runat="server"
            AutoGenerateColumns="False" CellPadding="4" GridLines="None" AllowPaging="True"
            OnPageIndexChanging="GrdState_PageIndexChanging" PageSize="20" EmptyDataText="Record is Not Available"
            Width="93%">
            <Columns>
                <asp:TemplateField HeaderText="Edit">
                    <ItemTemplate>
                        <asp:LinkButton ID="BtnEdit" runat="server" CausesValidation="false" class="black skin_colour round_all"
                            CommandArgument='<%# Eval("Country_ID")%>' CommandName="Edit1" ForeColor="#6699FF"
                            Font-Underline="True"> <span>Edit</span></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Delete">
                    <ItemTemplate>
                        <asp:LinkButton ID="BtnDelete" OnClientClick="return confirm('Are you sure want to delete?');"
                            CausesValidation="false" class="black skin_colour round_all " CommandArgument='<%# Eval("Country_ID")%>'
                            CommandName="Delete1" runat="server" ForeColor="#6699FF" Font-Underline="True"><span>Delete</span></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="View">
                    <ItemTemplate>
                        <asp:LinkButton ID="LBtnView" CausesValidation="false" class="black skin_colour round_all "
                            CommandArgument='<%# Eval("Country_ID")%>' CommandName="View1" runat="server"
                            ForeColor="#6699FF" Font-Underline="True"><span>View</span></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="Country_Name" HeaderText="Country" />
                <asp:BoundField DataField="Description" Visible="false" HeaderText="Description" />
                <asp:TemplateField HeaderText="Description">
                    <ItemTemplate>
                        <div class="DisplayDiv">
                            <asp:Label ID="Label1" runat="server" CssClass="DisplayDesc" Text='<%# Eval("Description") %>'></asp:Label>
                        </div>
                    </ItemTemplate>
                </asp:TemplateField>

                <asp:BoundField DataField="CreationDate" HeaderText="Creation Date" DataFormatString="{0:dd/MM/yy}" />
            </Columns>
        </asp:GridView>
    </ContentTemplate>
</asp:UpdatePanel>

The Code behind (If you can see I'm using command name for the link buttons in the grid view): 后面的代码(如果您可以看到我在网格视图中为链接按钮使用命令名):

public void EditGridData(object sender, GridViewCommandEventArgs e)
    {
        int i = Convert.ToInt32(e.CommandArgument);
        Session["Country_ID"] = i;

        if (e.CommandName == "Edit1")
        {
            SortedList sl = new SortedList();
            sl.Add("@mode", "GetRows1");
            sl.Add("@Country_ID", i);
            SqlDataReader dr = emp.GetDataReaderSP("CountryMaster1", sl);
            while (dr.Read())
            {
                txtCountry.Text = dr["Country_Name"].ToString();
                txtDesc.Text = dr["Description"].ToString();
                ViewState["Country_Name"] = dr["Country_Name"].ToString();
                BtnSubmit.Visible = true;
                BtnSubmit.Text = "Update";
            }
        }

        if (e.CommandName == "View1")
        {
            SortedList sl = new SortedList();
            sl.Add("@mode", "GetRows1");
            sl.Add("@Country_ID", i);
            SqlDataReader dr = emp.GetDataReaderSP("CountryMaster1", sl);
            while (dr.Read())
            {
                txtCountry.Text = dr["Country_Name"].ToString();
                txtDesc.Text = dr["Description"].ToString();
                ViewState["Country_Name"] = dr["Country_Name"].ToString();

                BtnReset.Visible = true;
                BtnSubmit.Visible = false;
            }
        }


        if (e.CommandName == "Delete1")
        {
            SortedList sl = new SortedList();
            sl.Add("@mode", "DeleteData");
            sl.Add("@Country_ID", i);

            emp.ExecuteNonQuerySP("CountryMaster1", sl);
            Label1.Visible = true;
            Label1.Text = "Record Deleted Successfully…";
            BindGrid();
        }

    }

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM