how to programatically call a gridview event from codebehind.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • phpmel
    New Member
    • Oct 2007
    • 69

    how to programatically call a gridview event from codebehind.

    hi guys,

    I have 2 gridviews, one inside a modal popup(gvSupplie rs) and one on the page(gvFirms). The header row of the gvFirms has 4 text boxes. I can find those controls easily inside the selectedindexCh anged method of gvSuppliers easilly when one row gvSupliers is selected. My problem arises when i try to find the 4 textboxes inside the emptydatatempla te of gvFirms.

    Eg.

    Code:
    protected void gvSuppliers_SelectedIndexChanged(object sender, EventArgs e)
        {
            GridViewRow row = gvSuppliers.SelectedRow;
            LinkButton linkbutton = (LinkButton)row.Cells[0].FindControl("LinkButton1");
            TextBox SupplierID = (TextBox)gvFirms.HeaderRow.FindControl("txtNewSupplierId");//This is the first textbox
    }
    My question is, inside gvSuppliers_Sel ectedIndexChang ed method, how do i find the textboxes inside the emptydatatempla te of gvFirms.

    one thought that crossed my mind was to programatically call the rowcommand event within the gvSuppliers_Sel ectedIndexChang ed method and so i should have the GridViewCommand EventArgs e and then i could say something to this effect inside gvFirms_Rowcomm and method

    Code:
     if (e.CommandName.Equals("AddNewItem"))
                {
                    GridViewRow row = (GridViewRow)((e.CommandSource as Button).NamingContainer);
    
                    string categoryName = (row.FindControl("txtCategoryName") as TextBox).Text;
    I dont know what to do
    Please help asap
    Last edited by phpmel; Aug 25 '08, 01:08 PM. Reason: addition
  • PRR
    Recognized Expert Contributor
    • Dec 2007
    • 750

    #2
    Code:
    if (e.CommandName.Equals("AddNewItem"))
                {
                    GridViewRow row = (GridViewRow)((e.CommandSource as Button).NamingContainer);
    
                    string categoryName = (row.FindControl("txtCategoryName") as TextBox).Text;
    
    Example :
    CheckBox  cblogin = ( CheckBox) gr.FindControl ("chkLogin");
    
    if(cblogin.checked)
    {
    
    }
    Textbox t=(TextBox)gr.FindControl ("Textbox1");
    
    string ss=t.text;
    or this may work ...
    Code:
     string categoryName = (row.FindControl("txtCategoryName") as TextBox).value ;// i dont recollect fully....
    i dont think i asnwered your question correctly... can you explain further....
    From what i understand.. i guess u will have to loop through all controls in gridview2 .... in case that is accessible to the original page..which i think is not?.
    Last edited by Curtis Rutland; Sep 2 '08, 03:00 PM. Reason: Added Code Tags - Please use the # button

    Comment

    • Curtis Rutland
      Recognized Expert Specialist
      • Apr 2008
      • 3264

      #3
      dirtbag,
      Please use code tags when posting code. It makes it easier for everyone to read. Also, it's part of the rules.

      MODERATOR

      Comment

      • PRR
        Recognized Expert Contributor
        • Dec 2007
        • 750

        #4
        Originally posted by insertAlias
        dirtbag,
        Please use code tags when posting code. It makes it easier for everyone to read. Also, it's part of the rules.

        MODERATOR
        ok i keep that in mind... thanks

        Comment

        Working...