----------------------------------------------------------- New Message on cochindotnet
----------------------------------------------------------- From: aspmatrix Message 1 in Discussion Hi sinoy Babu, check the code......... //aspx <asp:DataGrid id=dgProducts runat="server" Height="2px" CellPadding="3" BackColor="White" BorderWidth="1px" BorderStyle="None" BorderColor="#CCCCCC" AutoGenerateColumns="False" Width="552px"><SELECTEDITEMSTYLE BackColor="#669999" ForeColor="White" Font-Bold="True"></SELECTEDITEMSTYLE><ITEMSTYLE ForeColor="#000066"></ITEMSTYLE><HEADERSTYLE BackColor="#006699" ForeColor="White" Font-Bold="True"></HEADERSTYLE><FOOTERSTYLE BackColor="White" ForeColor="#000066"></FOOTERSTYLE><COLUMNS><asp:BoundColumn HeaderText="Product ID" ReadOnly="True" DataField="ProductID"></asp:BoundColumn><asp:BoundColumn HeaderText="Product Name" DataField="ProductName"></asp:BoundColumn><asp:TemplateColumn HeaderText="Category"><ITEMTEMPLATE><asp:Label id=lblCat runat="server" Width="128px" Text='<%# DataBinder.Eval(Container, "DataItem.CategoryName") %>'></asp:Label></ITEMTEMPLATE><EDITITEMTEMPLATE><asp:DropDownList id=ddlCategory runat="server" Width="134px"></asp:DropDownList></EDITITEMTEMPLATE></asp:TemplateColumn><asp:BoundColumn HeaderText="Unit Price" DataField="UnitPrice"></asp:BoundColumn><asp:EditCommandColumn EditText="Edit" CancelText="Cancel" UpdateText="Update" ButtonType="LinkButton"><asp:DataGrid id=dgProducts runat="server" Height="2px" CellPadding="3" BackColor="White" BorderWidth="1px" BorderStyle="None" BorderColor="#CCCCCC" AutoGenerateColumns="False" Width="552px"><SELECTEDITEMSTYLE BackColor="#669999" ForeColor="White" Font-Bold="True"></SELECTEDITEMSTYLE><ITEMSTYLE ForeColor="#000066"></ITEMSTYLE><HEADERSTYLE BackColor="#006699" ForeColor="White" Font-Bold="True"></HEADERSTYLE><FOOTERSTYLE BackColor="White" ForeColor="#000066"></FOOTERSTYLE><COLUMNS><asp:BoundColumn HeaderText="Product ID" ReadOnly="True" DataField="ProductID"></asp:BoundColumn><asp:BoundColumn HeaderText="Product Name" DataField="ProductName"></asp:BoundColumn><asp:TemplateColumn HeaderText="Category"><ITEMTEMPLATE><asp:Label id=lblCat runat="server" Width="128px" Text='<%# DataBinder.Eval(Container, "DataItem.CategoryName") %>'></asp:Label></ITEMTEMPLATE><EDITITEMTEMPLATE><asp:DropDownList id=ddlCategory runat="server" Width="134px"></asp:DropDownList></EDITITEMTEMPLATE></asp:TemplateColumn><asp:BoundColumn HeaderText="Unit Price" DataField="UnitPrice"></asp:BoundColumn><asp:EditCommandColumn EditText="Edit" CancelText="Cancel" UpdateText="Update" ButtonType="LinkButton"><asp:DataGrid id=dgProducts runat="server" Height="2px" CellPadding="3" BackColor="White" BorderWidth="1px" BorderStyle="None" BorderColor="#CCCCCC" AutoGenerateColumns="False" Width="552px"><SELECTEDITEMSTYLE BackColor="#669999" ForeColor="White" Font-Bold="True"></SELECTEDITEMSTYLE><ITEMSTYLE ForeColor="#000066"></ITEMSTYLE><HEADERSTYLE BackColor="#006699" ForeColor="White" Font-Bold="True"></HEADERSTYLE><FOOTERSTYLE BackColor="White" ForeColor="#000066"></FOOTERSTYLE><COLUMNS><asp:BoundColumn HeaderText="Product ID" ReadOnly="True" DataField="ProductID"></asp:BoundColumn><asp:BoundColumn HeaderText="Product Name" DataField="ProductName"></asp:BoundColumn><asp:TemplateColumn HeaderText="Category"><ITEMTEMPLATE><asp:Label id=lblCat runat="server" Width="128px" Text='<%# DataBinder.Eval(Container, "DataItem.CategoryName") %>'></asp:Label></ITEMTEMPLATE><EDITITEMTEMPLATE><asp:DropDownList id=ddlCategory runat="server" Width="134px"></asp:DropDownList></EDITITEMTEMPLATE></asp:TemplateColumn><asp:BoundColumn HeaderText="Unit Price" DataField="UnitPrice"></asp:BoundColumn><asp:EditCommandColumn EditText="Edit" CancelText="Cancel" UpdateText="Update" ButtonType="LinkButton"> <FORM id=Form1 method=post runat="server"><asp:DataGrid id=dgProducts runat="server" Height="2px" CellPadding="3" BackColor="White" BorderWidth="1px" BorderStyle="None" BorderColor="#CCCCCC" AutoGenerateColumns="False" Width="552px"><SELECTEDITEMSTYLE BackColor="#669999" ForeColor="White" Font-Bold="True"></SELECTEDITEMSTYLE><ITEMSTYLE ForeColor="#000066"></ITEMSTYLE><HEADERSTYLE BackColor="#006699" ForeColor="White" Font-Bold="True"></HEADERSTYLE><FOOTERSTYLE BackColor="White" ForeColor="#000066"></FOOTERSTYLE><COLUMNS><asp:BoundColumn HeaderText="Product ID" ReadOnly="True" DataField="ProductID"></asp:BoundColumn><asp:BoundColumn HeaderText="Product Name" DataField="ProductName"></asp:BoundColumn><asp:TemplateColumn HeaderText="Category"><ITEMTEMPLATE><asp:Label id=lblCat runat="server" Width="128px" Text='<%# DataBinder.Eval(Container, "DataItem.CategoryName") %>'></asp:Label></ITEMTEMPLATE><EDITITEMTEMPLATE><asp:DropDownList id=ddlCategory runat="server" Width="134px"></asp:DropDownList></EDITITEMTEMPLATE></asp:TemplateColumn><asp:BoundColumn HeaderText="Unit Price" DataField="UnitPrice"></asp:BoundColumn><asp:EditCommandColumn EditText="Edit" CancelText="Cancel" UpdateText="Update" ButtonType="LinkButton"><form id="Form1" method="post" runat="server"> <asp:DataGrid id="dgProducts" runat="server" Width="552px" AutoGenerateColumns="False" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" BackColor="White" CellPadding="3" Height="2px"> <SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#669999"></SelectedItemStyle> <ItemStyle ForeColor="#000066"></ItemStyle> <HeaderStyle Font-Bold="True" ForeColor="White" BackColor="#006699"></HeaderStyle> <FooterStyle ForeColor="#000066" BackColor="White"></FooterStyle> <Columns> <asp:BoundColumn DataField="ProductID" ReadOnly="True" HeaderText="Product ID"></asp:BoundColumn> <asp:BoundColumn DataField="ProductName" HeaderText="Product Name"></asp:BoundColumn> <asp:TemplateColumn HeaderText="Category"> <ItemTemplate> <asp:Label id="lblCat" runat="server" Width="128px" Text='<%# DataBinder.Eval(Container, "DataItem.CategoryName") %>'> </asp:Label> </ItemTemplate> <EditItemTemplate> <asp:DropDownList id="ddlCategory" runat="server" Width="134px"></asp:DropDownList> </EditItemTemplate> </asp:TemplateColumn> <asp:BoundColumn DataField="UnitPrice" HeaderText="Unit Price"></asp:BoundColumn> <asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn> </Columns> <PagerStyle HorizontalAlign="Left" ForeColor="#000066" BackColor="White" Mode="NumericPages"></PagerStyle> </asp:DataGrid> </form></asp:EditCommandColumn></COLUMNS><PAGERSTYLE BackColor="White" ForeColor="#000066" Mode="NumericPages" HorizontalAlign="Left"></PAGERSTYLE></asp:DataGrid></FORM></asp:EditCommandColumn></COLUMNS><PAGERSTYLE BackColor="White" ForeColor="#000066" Mode="NumericPages" HorizontalAlign="Left"></PAGERSTYLE></asp:DataGrid></asp:EditCommandColumn></COLUMNS><PAGERSTYLE BackColor="White" ForeColor="#000066" Mode="NumericPages" HorizontalAlign="Left"></PAGERSTYLE></asp:DataGrid></asp:EditCommandColumn></COLUMNS><PAGERSTYLE BackColor="White" ForeColor="#000066" Mode="NumericPages" HorizontalAlign="Left"></PAGERSTYLE></asp:DataGrid> //Code Behind public class WebForm1 : System.Web.UI.Page { protected System.Web.UI.WebControls.DataGrid dgProducts; private SqlConnection cn=new SqlConnection("server=localhost;uid=sa;pwd=password;database=Northwind"); private void Page_Load(object sender, System.EventArgs e) { if(!IsPostBack) { BindProducts(); } } private void BindProducts() { DataSet ds=new DataSet(); SqlDataAdapter da=new SqlDataAdapter("select ProductID,ProductName,CategoryName,UnitPrice from Products inner join Categories on Products.CategoryID=Categories.CategoryID",cn); da.Fill(ds,"product"); dgProducts.DataSource=ds.Tables["product"]; dgProducts.DataBind(); } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.dgProducts.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgProducts_EditCommand); this.dgProducts.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dgProducts_ItemDataBound); this.Load += new System.EventHandler(this.Page_Load); } #endregion private void dgProducts_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if(e.Item.ItemType==ListItemType.EditItem) { DropDownList ddl=(DropDownList)e.Item.FindControl("ddlCategory"); DataSet ds=new DataSet(); SqlDataAdapter da=new SqlDataAdapter("select CategoryID,CategoryName from categories",cn); da.Fill(ds,"category"); ddl.DataSource=ds.Tables["category"]; ddl.DataTextField="CategoryName"; ddl.DataValueField="CategoryID"; ddl.DataBind(); ddl.SelectedIndex=ddl.Items.IndexOf(ddl.Items.FindByText((string)ViewState["category"])); } } private void dgProducts_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { dgProducts.EditItemIndex=e.Item.ItemIndex; ViewState["category"]=((Label)e.Item.FindControl("lblCat")).Text; BindProducts(); } } Regards, Shiju Varghese, Digital mesh Movies, music, celeb news. Stay in the loop. With MSN Entertainment! ----------------------------------------------------------- To stop getting this e-mail, or change how often it arrives, go to your E-mail Settings. http://groups.msn.com/cochindotnet/_emailsettings.msnw Need help? If you've forgotten your password, please go to Passport Member Services. http://groups.msn.com/_passportredir.msnw?ppmprop=help For other questions or feedback, go to our Contact Us page. http://groups.msn.com/contact If you do not want to receive future e-mail from this MSN group, or if you received this message by mistake, please click the "Remove" link below. On the pre-addressed e-mail message that opens, simply click "Send". Your e-mail address will be deleted from this group's mailing list. mailto:[EMAIL PROTECTED]