locked
prepopulating the gridview column from a diffrent table..just one column RRS feed

  • Question

  • User186897 posted

    Hello

    I have a situation where there is a textbox and submit button, the textbox is to enter password and click submit. after submit gridview is displayed.

    the gridview has a column with field "Contact Name" this contact name should be displayed automatically depending on the code provided above

    Gridview is something like below...

    Date                     ContactName   Details         Status               Finish            Action

    prepopulate         prepopulate       textbox       textbox            textbox           Add Record(button)

    how do i prepopulate the date column and ContactName column(contact name comes from a table where name is derived from the code entred in the textbox)

    I know its confusing but if someone can plz help me how to prepolated the firld from a different datasource or query...thanks

    Thursday, June 23, 2016 9:00 AM

All replies

  • User-1034726716 posted

    You mean populate your Grid with ContactName based on the password entered from a TextBox? 

    Thursday, June 23, 2016 12:19 PM
  • User61956409 posted

    Hi Lexi85,

    I have a situation where there is a textbox and submit button, the textbox is to enter password and click submit. after submit gridview is displayed.

    the gridview has a column with field "Contact Name" this contact name should be displayed automatically depending on the code provided above

    Gridview is something like below...

    Date                     ContactName   Details         Status               Finish            Action

    prepopulate         prepopulate       textbox       textbox            textbox           Add Record(button)

    It seems that you’d like to dynamically insert new row using ASP.Net GridView control, you could refer to this article.

    http://www.aspsnippets.com/Articles/Add-record-to-Database-using-ASP.Net-GridView-EmptyDataTemplate-and-FooterTemplate.aspx

    And you could specify value for Date and ContactName on btnsubmit click event.

    protected void btnsubmit_Click(object sender, EventArgs e)
    {
        Control control = null;
    
        if (GridView1.FooterRow != null)
        {
            control = GridView1.FooterRow;
        }
        else
        {
            control = GridView1.Controls[0].Controls[0];
        }
    
        //here you could retrieve Date and ContactName based on the code user provides 
        //populate Date and ContactName column of gridview
        (control.FindControl("txtdate") as TextBox).Text = "date";
    
        (control.FindControl("txtCName") as TextBox).Text = "ContactName";
    }
    

    Best Regards,

    Fei Han

    Friday, June 24, 2016 2:46 AM