Click here to Skip to main content
15,562,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello there,

Case

I have web form that shows some record from database using a gridview.
1. I have given search facility in form using a textbox and button control. When user enter something in textbox and click on button the gridview updates with search results.
2. My gridview is inside a update panel.
3. I have given edit and delete record in using gridview link buttons.When user click on edit link
the page redirect to edit form with record id using query string.
4. The Gridview paging is enabled.
5. I have used dataset to fill the gridview.

While showing all records everything (Search, Edit, Delete) is working fine. But when user search for some record and click on edit link the rowcommand gets command argument of gridview having all record i.e previous state before search and final it redirects to edit form with wrong id.

Code:
Search Button Click Event:

C#
protected void Button1_Click(object sender, EventArgs e)
                {
  
                     refreshbothdd();
                     string SearchData;
                     int SearchIn;
                     SearchData = TextBox1.Text;
                     SearchIn = DropDownList3.SelectedIndex;
                     switch(SearchIn)
                     {
                     case 1:
                      
                     FillGrid(4,SearchData );
                     break;
                     case 2 :
                     FillGrid(5,SearchData );
                     break;
                 }


Method to fill the grid according to Different Queries:

C#
public void FillGrid(int temp, string tempData)
             {
                     switch (temp)
                     {
                     case 0:
                     da = new SqlDataAdapter("Select SRNo, DepositeType, PartyName, AccOf, CreditOf, DepositeDt,BankName,BranchName,ChequeNo,Amount,DepositeBy from ChTable order by SRNo desc ", conn);
                     break;
                     case 1:
                     da = new SqlDataAdapter("Select SRNo, DepositeType,PartyName,AccOf,CreditOf,DepositeDt,BankName,BranchName,ChequeNo,Amount,DepositeBy from ChTable where DepositeBy='" + tempData + "' order by SRNo desc", conn);
                     break;
                     case 2:
                     da = new SqlDataAdapter("Select SRNo, DepositeType,PartyName,AccOf,CreditOf,DepositeDt,BankName,BranchName,ChequeNo,Amount,DepositeBy from ChTable where AccOf='" + tempData + "' order by SRNo desc", conn);
                      
                     break;
                     case 3:
                     da = new SqlDataAdapter("Select SRNo, DepositeType,PartyName,AccOf,CreditOf,DepositeDt,BankName,BranchName,ChequeNo,Amount,DepositeBy from ChTable where DepositeType='" + tempData + "' order by SRNo desc", conn);
                     break;
                     case 4:
                     da = new SqlDataAdapter("Select SRNo, DepositeType,PartyName,AccOf,CreditOf,DepositeDt,BankName,BranchName,ChequeNo,Amount,DepositeBy from ChTable where ChequeNo like '%" + tempData + "%' order by SRNo desc", conn);
                     break;
                     case 5:
                     da = new SqlDataAdapter("Select SRNo, DepositeType,PartyName,AccOf,CreditOf,DepositeDt,BankName,BranchName,ChequeNo,Amount,DepositeBy from ChTable where PartyName like '%" + tempData + "%' order by SRNo desc", conn);
                     break;
                     case 6:
                     da = new SqlDataAdapter("Select SRNo, DepositeType,PartyName,AccOf,CreditOf,DepositeDt,BankName,BranchName,ChequeNo,Amount,DepositeBy from ChTable where DepositeDt between '" + fromdt.Text + "' and '" + todt.Text + "' order by SRNo desc", conn);
                     break;
                     }                     
                    
                     GridView1.DataSource = null;
                     GridView1.DataBind();
                      
                     ds = new DataSet();
                     da.Fill(ds);
                     GridView1.DataSource = ds.Tables[0];
                     GridView1.DataBind();                      
                    
             }


The GridView Rowcommand For Edit:

C#
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
                 {
                          
                         if (e.CommandName == "Edit")
                         {
                         string SRID = e.CommandArgument.ToString();
                         Response.Redirect("EditTransact.aspx/?Transaction=" + SRID + "");
                         }
                  
                 }



[Edit] Code posted in the comment is added here for better understanding[/Edit]
Posted
Updated 5-Jun-14 3:39am
v2
Comments
DamithSL 5-Jun-14 5:05am    
Can you explain with your code? then it is easy to give solution.

1 solution

Hello friend, it seems like there is some problem using the ajax UpdatePanel control I would suggest to disable the ajax on the page for sometime and try to test the functionality first. If it works fine after disabling ajax then you will be confirmed that there is some problem in using ajax only.
You can disable all ajax controls by adding EnablePartialRendering="false" in ScriptManager control as follows:
ASP.NET
<asp:scriptmanager id="ScriptManager1" runat="server" enablepartialrendering="false" xmlns:asp="#unknown"></asp:scriptmanager>
 
Share this answer
 
Comments
Raghubir_Sarkar 6-Jun-14 1:46am    
Thanks Mr. Das I tried your solution, it's not working for my problem. So it's not a problem of Update panel.
Raghubir_Sarkar 6-Jun-14 1:48am    
Is there any problem with Gridview databinding method?. I think in search the gridview doesn't update it's just showing the required result.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900