Ask a questionAsk a question
 

QuestionSharepoint Gridview

  • Monday, November 02, 2009 4:46 AMSAAD TAHIR Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    hey..
    i m using gridview in my web part... everything is working fine.. but the update event not working..
    edit n cancle n all event are working fine in my web part.. when i click update button nothing happen. postback occur bt nothing happend.
    wats the error ?
    thanks

All Replies

  • Monday, November 02, 2009 5:10 AMKarine BoschMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi Saad,

    Can you please post your code so that we can verify where perhaps it goes wrong?


    Karine Bosch
  • Monday, November 02, 2009 5:17 AMSAAD TAHIR Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    protected override void CreateChildControls()
            {
    this.gridvw.RowUpdating += new GridViewUpdateEventHandler(gridvw_RowUpdating);
                this.gridvw.RowUpdated += new GridViewUpdatedEventHandler(gridvw_Rowupdated);
                this.gridvw.RowEditing += new GridViewEditEventHandler(gridvw_RowEditing);
                this.gridvw.PageIndexChanging += new GridViewPageEventHandler(gridvw_PageIndexChanging);
                this.gridvw.RowCancelingEdit += new GridViewCancelEditEventHandler(gridvw_CancleRowEditing);
    }
     protected override void RenderContents(HtmlTextWriter writer)
            {
    making connection to database . connection datasource to grid n bind data perform in this tag..
    }
    protected void gridvw_RowUpdating(object sender, GridViewUpdateEventArgs e)
            {
                TextBox txtname = ((TextBox)gridvw.Rows[e.RowIndex].FindControl("txtname"));
                TextBox age = ((TextBox)gridvw.Rows[e.RowIndex].FindControl("age"));
                TextBox desig = ((TextBox)gridvw.Rows[e.RowIndex].FindControl("desig"));

                string update = "Update Testtable set Name='" + txtname + "',Age='" + age + "',Designation='" + desig + "' Where ID="
                    + this.gridvw.DataKeys[e.RowIndex].Value;

                SqlConnection con1 = new SqlConnection(conn1);
               
                    SqlCommand com = new SqlCommand(update, con1);
                    con1.Open();
                    com.ExecuteNonQuery();
                    con1.Close();
               
                this.gridvw.EditIndex = -1;
                this.gridvw.DataBind();
             }
  • Monday, November 02, 2009 6:02 AMKarine BoschMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Your code seems ok to me. When you place a breakpoint in the Update method and attach the Debugger to the SharePoint process and click the update button again, does the debugger hit your breakpoint?


    Karine Bosch
  • Monday, November 02, 2009 6:10 AMSAAD TAHIR Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    no... its not hitting the breakpoint too .. and also not hitting breakpoint for any other event ...
  • Monday, November 02, 2009 6:17 AMKarine BoschMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    1) Where do you declare the gridvw variable? Is this a class level variable?
    2) Where do you initialize this gridvw variable?


    Karine Bosch
  • Monday, November 02, 2009 6:17 AMPaul Keijzers KbWorks Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Most possible your code is not deployed correctly else it should hit that breakpoint.
    do you debug with attached to w3p.exe?

    kind regards,

    Paul Keijzers
    Check my website http://www.kbworks.nl or follow me on @KbWorks be sure to Check my KbWorks blog
  • Monday, November 02, 2009 6:19 AMconverscient Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    have you attached your debugger to the server remotely? since you said all your other events are working fine, then the breakpoint should be hit.
    When you click the update button, do the page do a postback or anything of that sort?

    Never stop learning.
  • Monday, November 02, 2009 6:22 AMSAAD TAHIR Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    gridvw declare in class and initialize in createchildmthod
  • Monday, November 02, 2009 6:23 AMSAAD TAHIR Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    how to attach w3p.exe process to debuger
  • Monday, November 02, 2009 6:25 AMSAAD TAHIR Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    no m nt attch with to server remotely. yeah when i hit update a postback occur
  • Monday, November 02, 2009 6:27 AMconverscient Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    http://blogs.msdn.com/sharepoint/archive/2007/04/10/debugger-feature-for-sharepoint.aspx

    Can you do a simple test, comment all the codes in your update event handler and Response.write something to see if it triggers. If it doesn't, your declaration or intialization might have problems. If it does, your SQL connection/queries might have problem :)
    Never stop learning.
  • Monday, November 02, 2009 6:31 AMSAAD TAHIR Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    its not hitting the update event .. i found after debug it with w3p.exe process. and hitting all others event.
  • Monday, November 02, 2009 6:33 AMconverscient Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Can you show the rendercontents block?
    Never stop learning.
  • Monday, November 02, 2009 6:35 AMKarine BoschMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi Saad,

    Can you please post the complete declaration of your gridview, including the properties you set?

    Karine Bosch
  • Monday, November 02, 2009 6:35 AMSAAD TAHIR Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    protected override void RenderContents(HtmlTextWriter writer)
            {
    conn = new SqlConnection(conn1);
                                conn.Open();
    comm = new SqlCommand(query1, conn);
    new SqlDataAdapter(query1, conn1).Fill(this.datatab);
                                this.gridvw.DataSource = this.datatab;
                                this.gridvw.DataBind();
    conn.Close();
    his.gridvw.RenderControl(writer);
    }
  • Monday, November 02, 2009 6:37 AMKarine BoschMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi Saad,

    Can you please post the complete declaration of your gridview, including the properties you set?
    Karine Bosch
  • Monday, November 02, 2009 6:37 AMconverscient Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    like what Karine Bosch said, you might want to post the declaration of your gridview and see what's wrong with it.

    Never stop learning.
  • Monday, November 02, 2009 6:41 AMSAAD TAHIR Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    public class SQL : System.Web.UI.WebControls.WebParts.WebPart
        {
            public SQL()
            {
            }
    GridView gridvw;
    protected override void CreateChildControls()
            {this.Controls.Add(this.gridvw);
                this.gridvw.AutoGenerateColumns = true;
                this.gridvw.AllowPaging = true;
                this.gridvw.HeaderStyle.Font.Bold=true;
                this.gridvw.ShowHeader = true;
                this.gridvw.ShowFooter = true;
                this.gridvw.Visible = true;
                this.gridvw.CellPadding = 2;
                this.gridvw.CellSpacing = 2;
                this.gridvw.GridLines = GridLines.Both;
                this.gridvw.BorderColor = Color.Black;
                this.gridvw.BorderWidth =2;
                this.gridvw.AutoGenerateDeleteButton = true;
                this.gridvw.AutoGenerateEditButton = true;
                this.gridvw.AutoGenerateSelectButton = true;
                this.gridvw.Width = 25;
    this.gridvw.RowUpdating += new GridViewUpdateEventHandler(gridvw_RowUpdating);
                this.gridvw.RowUpdated += new GridViewUpdatedEventHandler(gridvw_Rowupdated);
                this.gridvw.RowEditing += new GridViewEditEventHandler(gridvw_RowEditing);
                this.gridvw.PageIndexChanging += new GridViewPageEventHandler(gridvw_PageIndexChanging);
                this.gridvw.RowCancelingEdit += new GridViewCancelEditEventHandler(gridvw_CancleRowEditing);
                this.gridvw.RowDeleting += new GridViewDeleteEventHandler(gridvw_RowDelete);
    }
  • Monday, November 02, 2009 6:46 AMconverscient Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    hmm, where your update button come into the picture?

    Never stop learning.
  • Monday, November 02, 2009 6:48 AMSAAD TAHIR Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    this.gridvw.AutoGenerateEditButton = true;
    ohh ... when  i click edit button it give 2 option cancel or update..... :S
  • Monday, November 02, 2009 6:50 AMconverscient Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    since you are doing some test methods.. why don't you do a simple .NET app that can produce what is desired before bringing the codes over to webpart programming? Easier and faster to development this way, when you are trying to bring over to webpart dev, you will still go through some hiccups and learn along the way :)

    Never stop learning.
  • Monday, November 02, 2009 6:52 AMSAAD TAHIR Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    allrite :) Thanks for the help .. :)
  • Monday, November 02, 2009 6:56 AMKarine BoschMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi Saad,
    Does this mean your problem is solved? In that case can you mark the answer that helped you most?
    Greetz,


    Karine Bosch
  • Monday, November 02, 2009 7:00 AMSAAD TAHIR Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    not yet solved.. when it ll gt solved i ll mark it as answer
  • Monday, November 02, 2009 7:24 AMSAAD TAHIR Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    its woking fine in web application.. but in web part its not hitting the event.. :(
  • Wednesday, November 04, 2009 1:46 AMAaron Han - MSFTModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi,Saad

     

    As Karine Bosch said, your logic seems ok so please confirm if your event is really not hitting or your gridvw_Rowupdated method did not execute the database update logic.

    Would you please also check your log file (Driver:\Program Files\Common Files\Microsoft Shared\web server extensions\12\LOGS) to see if you can get some clues there.

     

    Best Regards,

    -Aaron

  • Wednesday, November 04, 2009 2:58 AMconverscient Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Can you do a simple test, in the update event, do a response.write("something") and see whether anything appears on your sharepoint. You also have to check whether you did a proper webpart deployment.. is the dll modified date latest?
    Never stop learning.
  • Wednesday, November 04, 2009 4:25 PMSAAD TAHIR Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    yeh the updating event wasnt firing. on asp web its working fine bt on sharepoint web part its nt working.
  • Thursday, November 05, 2009 5:06 AMAaron Han - MSFTModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi,Saad

     

        As your desrioption on asp web its working fine

        How did you test on your web app, also a webpart or webpart or usercontrol?

        If all solutions did not work, would you please try other direction: create a webpart with usercontrol as a walkaround.    

        Hope this can hlep.
     

    Best Regards,

     

    -Aaron