Pass (Send) GridView data to another Page using QueryString in ASP.Net

Last Reply one month ago By pandeyism

Posted one month ago

I want to send gridview data on editbutton click.

<asp:GridView ID="GridView1" runat="server" BackColor="SlateGray" BorderColor="Gray"
    BorderStyle="None" BorderWidth="10px" CellPadding="4" AutoGenerateColumns="False"
    DataKeyNames="Id" Font-Size="X-Large" CssClass="mydatagrid" PagerStyle-CssClass="pager"
    OnRowCommand="GridView1_RowCommand" HeaderStyle-CssClass="header" RowStyle-CssClass="rows"
    Width="100%">
    <Columns>
        <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name">
            <HeaderStyle HorizontalAlign="Center" />
            <ItemStyle HorizontalAlign="Center" />
        </asp:BoundField>                    
        <asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address">
            <HeaderStyle HorizontalAlign="Center" />
            <ItemStyle HorizontalAlign="Center" />
        </asp:BoundField>
        <asp:TemplateField HeaderText="Accept">
            <ItemTemplate>
                <center>
                    <a href="?id=<%#Eval("id") %>">
                        <asp:Button ID="btnEdit" runat="server" class="btn btn-primary" Width="100px" Font-Size="20px"
                            Text="View" CommandName="EditButton" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" />
                </center>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
    SelectCommand="SELECT [Id], [Name], [PQuantity], [State], [District], [Address], [Contact], [Email] FROM [Company_Data199]">
</asp:SqlDataSource>

 

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "EditButton")
    {
        int index = Convert.ToInt32(e.CommandArgument);
        GridViewRow row = GridView1.Rows[index];
        Response.Redirect("~/AddRawMaterial.aspx?Id=" + e.CommandArgument.ToString());
    }
}

second form

protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
        string constr = ConfigurationManager.ConnectionStrings["Mycon"].ConnectionString;
        using (SqlConnection conn = new SqlConnection(constr))
        {
            using (SqlDataAdapter sda = new SqlDataAdapter("SELECT AddRaw_199.Name,AddRaw_199.Id,Company_Data199.PQuantity,AddRaw_199.Address,AddRaw_199.Contact,AddRaw_199.District,AddRaw_199.Email,AddRaw_199.State,AddRaw_199.Quantity,Company_Data199.PQuantity,Total=AddRaw_199.Quantity*Company_Data199.PQuantity FROM AddRaw_199 INNER JOIN Company_Data199 ON AddRaw_199.Id = Company_Data199.PQuantity where AddRaw_199.Status = 0 and AddRaw_199.Id=; " + Request.QueryString["Id"].ToString() + "'", conn))
            {
                DataTable dt = new DataTable();
                sda.Fill(dt);
                gvData.DataSource = dt;
                gvData.DataBind();
            }
        }
    }
}

 

You are viewing reply posted by: pandeyism one month ago.