Click here to Skip to main content
15,913,669 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a dynamic gridview with rows and i want to perform edit record in with in the gridview.

Note: I am not creating columns for gridview

how to do this
Posted

Hi,

Go with this link learn carefully your answer is here is to create text controls like objects in gridview in asp.net :

http://www.aspdotnet-suresh.com/2011/02/how-to-inserteditupdate-and-delete-data.html[^]


Best of Luck!
 
Share this answer
 
Your link is ok,I want create dropdown with data in dynamic gridview
 
Share this answer
 
XML
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
            onrowdatabound="GridView1_RowDataBound1">
            <Columns>
                <asp:BoundField DataField="CODE" HeaderText="CODE" />
                <asp:BoundField DataField="REFCODE" HeaderText="REFCODE" />
            <asp:TemplateField>
            <ItemTemplate>
             <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
                    onselectedindexchanged="DropDownList1_SelectedIndexChanged" Width="200px">
                </asp:DropDownList>
            </ItemTemplate>
            </asp:TemplateField>
                 </Columns>
</asp:GridView>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public partial class Default3 : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection("--------------------------------");
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            con.Open();
            SqlCommand cmd = new SqlCommand(" write your query", con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            con.Close();
            GridView1.DataSource = ds;
            GridView1.DataBind();
        }
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void GridView1_RowDataBound1(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            con.Open();
            var ddl = (DropDownList)e.Row.FindControl("DropDownList1");
            int CountryId = Convert.ToInt32(e.Row.Cells[0].Text);
            SqlCommand cmd = new SqlCommand(" write your query ", con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            ddl.DataSource = ds;
            ddl.DataTextField = "xxxxx";
            ddl.DataValueField = "xxxxx";
            ddl.DataBind();
            con.Close();
        }
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900