hi Frd.,

i have done web page which will add values to the gridview once we select the add button it will open the popup after entering the pop-up it should display values in parent page once we return... But its not displaying
just have look guys and solve the problems as soon as possible


Default.aspx

have used two hidden fields and they are hdn1 and hdn2 and gridview i didnt add the columns directly to add gridview every things is done in programmatically



public partial class _Default : System.Web.UI.Page 
{
    DataSet ds = new DataSet();
    public string datatablename = "empdata";
    DataTable dt;
    DataView dv;
    DataRow dr;
    DataColumn dc;
    public string dc0,dc1,dc2;


    protected void Page_Load(object sender, EventArgs e)
    {
        designcols();
        Button1.Attributes.Add("onclick", "window.open('Default2.aspx',null,'left=400px,top=400,height=100px,width-250,status=no,resizable=no,scrollbars=no;toolbar=no,location=no,menubar=no');");
        loadval();
       
    }

    public void designcols()
    {
        dt = new DataTable(datatablename);
        dc = dt.Columns.Add("EMP", typeof(string));
        dt.Columns.Add("empname",typeof(string));
        dt.Columns.Add("Empaddr", typeof(string));
        ds.Tables.Add(dt);
        //dr = dt.NewRow();
        //ds.Tables[datatablename].Rows.Add(dr);        
    }
    public void loadval()
    {
        

            if (ViewState["datatablename"] != null)
            {
                DataTable Tempdt = new DataTable();
                Tempdt = ViewState["datatablename"] as DataTable;
                dt = Tempdt.Copy();
            }
            dr = dt.NewRow();
            dr[0] = hdn1.Value;
            dr[1] = hdn2.Value;
            dr[2] = dc2;
            dt.Rows.Add(dr);
            ViewState["datatablename"] = dt;
            dv = new DataView(dt);
            GridView1.DataSource = dv;
            GridView1.DataBind();
       

    }

Default2.aspx in html page i wrote this

Two textbox as textbox1 and textbox2

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript">
    function passvalue()
    {
    
    window.opener.document.getElementById("hdn1").value=document.getElementById("<%=TextBox1.ClientID %>").value;
    window.opener.document.getElementById("hdn2").value=document.getElementById("<%=TextBox2.ClientID %>").value;
    window.self.close();  
    }    
    </script>
</head>

in page load i have added this

protected void Page_Load(object sender, EventArgs e)
    {
        Button1.Attributes.Add("onclick", "passvalue();");
    }

check this code or mail me i will send u back the Webpage which i have errors....


Never Give Up

try this code for which i had done in my computer i'm using textbox you can use any thing as per you want

private void BindGrid(int rowcount)
{
        DataTable dt = new DataTable();
        DataRow dr;
        dt.Columns.Add(new System.Data.DataColumn("TextBox1Column", typeof(String)));
        dt.Columns.Add(new System.Data.DataColumn("TextBox2Column", typeof(String)));
        dt.Columns.Add(new System.Data.DataColumn("TextBox3Column", typeof(String)));
 
        if (ViewState["CurrentData"] != null)
        {
            for (int i = 0; i < rowcount + 1; i++)
            {
                dt = (DataTable)ViewState["CurrentData"];
                if (dt.Rows.Count > 0)
                {
                    dr = dt.NewRow();
                    dr[0] = dt.Rows[0][0].ToString();
 
                }
            }
            dr = dt.NewRow();
            dr[0] = TextBox1.Text;
            dr[1] = TextBox2.Text;
            dr[2] = TextBox3.Text;
            dt.Rows.Add(dr);
 
        }
        else
        {
            dr = dt.NewRow();
            dr[0] = TextBox1.Text;
            dr[1] = TextBox2.Text;
            dr[2] = TextBox3.Text;
 
            dt.Rows.Add(dr);
 
        }
 
        // If ViewState has a data then use the value as the DataSource
        if (ViewState["CurrentData"] != null)
        {
            GridView1.DataSource = (DataTable)ViewState["CurrentData"];
            GridView1.DataBind();
        }
        else
        {
        // Bind GridView with the initial data assocaited in the DataTable
            GridView1.DataSource = dt;
            GridView1.DataBind();
 
        }
        // Store the DataTable in ViewState to retain the values
        ViewState["CurrentData"] = dt;
 
    }

Binding the GridView on Button_Click event

protected void Button1_Click(object sender, EventArgs e)
    {
        // Check if the ViewState has a data assoiciated within it. If 
        if (ViewState["CurrentData"] != null)
        {
            DataTable dt = (DataTable)ViewState["CurrentData"];
            int count = dt.Rows.Count;
            BindGrid(count);
        }
        else
        {
            BindGrid(1);
        }
        TextBox1.Text = string.Empty;
 
        TextBox1.Focus();
}

mark thread as solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.