You must Sign In to post a response.
  • Category: .NET

    Saving the text given in modal pop up to gridview

    in my application i have a button when user clicks on the button we should get a modal pop with 4 text boxes,after entering the text in these text boxes when user click on add button the pop up should be disappered and the text should be saved in grid view every thing is done and here is my complete code but currently my grid view is in modalup that is webform2.aspx but i need gridview in webform1.aspx if i am placing my grid view in web form1 i am getting an error that the name 'GridView1' does not exist in the current context but i compulsorily need this gridview in web form1.aspx only can anyone please help me out

    in first web form-where user can click a button

    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>


    <!DOCTYPE html>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <title></title>
    <style type="text/css">

    .Background

    {

    background-color: Black;

    filter: alpha(opacity=90);

    opacity: 0.8;

    }

    .Popup

    {

    background-color: #FFFFFF;

    border-width: 3px;

    border-style: solid;

    border-color: black;

    padding-top: 10px;

    padding-left: 10px;

    width: 400px;

    height: 350px;

    }

    .lbl

    {

    font-size:16px;

    font-style:italic;

    font-weight:bold;

    }

    </style>
    </head>
    <body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">

    </asp:ScriptManager>
    <asp:Button ID="Button1" runat="server" Text="Fill Form in Popup" />



    <cc1:ModalPopupExtender ID="mp1" runat="server" PopupControlID="Panl1" TargetControlID="Button1"

    CancelControlID="Button2" BackgroundCssClass="Background">

    </cc1:ModalPopupExtender>

    <asp:Panel ID="Panl1" runat="server" CssClass="Popup" align="center" style = "display:none">

    <iframe style=" width: 350px; height: 300px;" id="irm1" src="WebForm2.aspx" runat="server"></iframe>

    <br/>

    <asp:Button ID="Button2" runat="server" Text="Close" />

    </asp:Panel>

    </form>
    </body>

    in my webform2.aspx

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <title></title>
    <script type = "text/javascript">
    function Hidepopup() {
    $find("popup").hide();
    return false;
    }
    </script>

    </head>
    <body>
    <form id="form1" runat="server">
    <div id="irm1" style=" width: 300px; height: 250px;" runat="server" >
    <table>

    <tr>

    <td>



    <asp:Label ID="Label1" runat="server" CssClass="lbl" Text="First Name"></asp:Label>


    </td>

    <td>

    <asp:TextBox ID="TextBox1" runat="server" Font-Size="14px" ></asp:TextBox>

    </td>

    </tr>

    <tr>

    <td>

    <asp:Label ID="Label2" runat="server" CssClass="lbl" Text="Middle Name"></asp:Label>

    </td>

    <td>

    <asp:TextBox ID="TextBox2" runat="server" Font-Size="14px" ></asp:TextBox>

    </td>

    </tr>

    <tr>

    <td>

    <asp:Label ID="Label3" runat="server" CssClass="lbl" Text="Last Name"></asp:Label>

    </td>

    <td>

    <asp:TextBox ID="TextBox3" runat="server" Font-Size="14px" ></asp:TextBox>

    </td>

    </tr>

    <tr>

    <td>

    <asp:Label ID="Label4" runat="server" CssClass="lbl" Text="Gender"></asp:Label>

    </td>

    <td>

    <asp:TextBox ID="TextBox4" runat="server" Font-Size="14px" ></asp:TextBox>

    </td>

    </tr>

    <tr>

    <td>

    </td>

    <td>

    <asp:Button ID="Button1" runat="server" Text="Add" OnClick="btn1_Click" />

    </td>

    </tr>

    <tr>

    <td>

    </td>

    <td>

    <asp:Label ID="Label5" runat="server"></asp:Label>

    </td>

    </tr>

    </table>

    <div style="margin-left:10px;margin-top:10px">
    <asp:GridView ID="GridView1" AutoGenerateColumns="false" runat="server" CellPadding="2"
    ForeColor="#333333" GridLines="None">
    <AlternatingRowStyle BackColor="White" />
    <Columns>
    <asp:BoundField HeaderStyle-Width="120px" HeaderText="FirstName" DataField="FirstName" />
    <asp:BoundField HeaderStyle-Width="120px" HeaderText=" MiddleName" DataField="MiddleName" />
    <asp:BoundField HeaderStyle-Width="120px" HeaderText=" LastName" DataField="LastName" />
    <asp:BoundField HeaderStyle-Width="120px" HeaderText="Gender" DataField="Gender" />
    </Columns>
    <EditRowStyle BackColor="#2461BF" />
    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
    <RowStyle BackColor="#EFF3FB" />
    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
    <SortedAscendingCellStyle BackColor="#F5F7FB" />
    <SortedAscendingHeaderStyle BackColor="#6D95E1" />
    <SortedDescendingCellStyle BackColor="#E9EBEF" />
    <SortedDescendingHeaderStyle BackColor="#4870BE" />
    </asp:GridView>
    </div>
    </div>
    </form>
    </body>

    and my code behind-

    protected void Page_Load(object sender, EventArgs e)
    {
    dt = new DataTable();
    DataColumn dc1 = new DataColumn("FirstName");
    DataColumn dc2 = new DataColumn("MiddleName");
    DataColumn dc3 = new DataColumn("LastName");
    DataColumn dc4 = new DataColumn("Gender");
    dt.Columns.Add(dc1);
    dt.Columns.Add(dc2);
    dt.Columns.Add(dc3);
    dt.Columns.Add(dc4);
    DataRow dr1 = dt.NewRow();
    GridView1.DataSource = dt;
    GridView1.DataBind();
    }
    DataTable dt;

    protected void btn1_Click(object sender, EventArgs e)
    {
    DataRow dr1 = dt.NewRow();
    dr1[0] = TextBox1.Text;
    dr1[1] = TextBox2.Text;
    dr1[2] = TextBox3.Text;
    dr1[3] = TextBox4.Text;
    dt.Rows.Add(dr1);
    GridView1.DataSource = dt;
    GridView1.DataBind();

    }
    protected void ClearFields()
    {
    TextBox1.Text = "";
    TextBox2.Text = "";
    TextBox3.Text = "";
    TextBox4.Text = "";
    }

    now i need to hide the pop up after clicking the add button and place my gridview in webform1.aspx how can i do this
  • #767094
    Take a datatable
    datatype is not mandatory
    Datatable dt =new Datatable();
    dt.columns.add("columnname",datatype);
    dt.columns.add() like this...

    after
    Datarow dr = dt.newrow();
    dr[0] = ;
    dr[1]=
    dr[2]=

    like this and add to datatable
    dt.rows.add(dr);
    dt.acceptchanges();
    your text is saved in datatable.......
    for furhter reference you can see the below links...
    http://www.dotnetspider.com/resources/46134-DataTableClone-vs-DataTableCopy.aspx
    http://www.dotnetspider.com/resources/46079-How-to-work-with-sliding-textbox-in-JQuery-using-aspnet-C.aspx

    SRI RAMA PHANI BHUSHAN KAMBHAMPATI

  • #767095
    You can do it in two ways.
    In tho first way you can force the post back so the page will be post back you can read the text box values and save that values
    In the second way you can do Jquery Ajax call by sending the input as Json by getting the values from the text box. In the Ajax call you can save the values in the database using Web method. Following is the sample Jquery Ajax call with JSON input.

    $.ajax({
    type: "post",
    url: "SaveDB.aspx/SaveValuesIntoDB,
    contentType: "application/json; charset=utf-8",
    dataType: "html",
    data: '{"format":"' + //getvalue from DB + '"}',
    success: function (result) {
    if (result != '') {

    }
    },
    error: function (xhr, status, error) {
    //alert("Error");
    }
    });

    By Nathan
    Direction is important than speed

  • #767101
    Hi,

    To implement the above task my suggestion is go through AJAX Modal Popup extender control that was help you alot to implement the above task, I will share you some sample code for your reference.


    <asp:Button ID="btnShowPopup" Text="Show Popup" runat="server" />
    <cc1:ModalPopupExtender ID="mpe" runat="server" TargetControlID="btnShowPopup"
    PopupControlID="pnlPopup" BackgroundCssClass="modalBackground">
    </cc1:ModalPopupExtender>
    <asp:Panel ID="pnlPopup" runat="server" >
    <table>

    <tr>
    <td>
    <asp:TextBox ID="txt1" runat="server"></asp: TextBox >
    </td>
    </tr>
    <tr>
    <td>
    <asp:TextBox ID="txt1" runat="server"></asp: TextBox >
    </td>
    </tr>
    <tr>
    <td colspan="2">
    </td>
    </tr>
    <tr>
    <td>
    <asp:Button ID="btnSave" OnClick="btnSave_Click" runat="server" />
    </td>
    </tr>
    </table>
    </asp:Panel>



    design your code like above and on click event of button you can save your data into table.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/


  • Sign In to post your comments