Wrox Programmer Forums
.NET Framework 1.x For discussing versions 1.0 and 1.1 of the Microsoft .NET Framework.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 1.x section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old December 9th, 2006, 01:55 AM
Friend of Wrox
Join Date: Feb 2006
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to gaurav_jain2403
Default DataGrid Editing Problem

Hi friends,
I am using a datagrid in my application. I want that one column("ID") cannot be edited by anyone. The design of the Datagrid was as follow:

<asp:DataGrid id="DataGrid1" runat="server" OnCancelCommand="DataGrid1_CancelCommand" OnDeleteCommand="DataGrid1_DeleteCommand" OnEditCommand="DataGrid1_EditCommand" OnUpdateCommand="DataGrid1_UpdateCommand" CellPadding="4" BackColor="White" BorderWidth="1px" BorderStyle="None" BorderColor="#CC9966" AllowSorting="True" AllowPaging="True" AutoGenerateColumns="False" PageSize="2" OnPageIndexChanged="DataGrid1_PageIndexChanged">
                        <ItemStyle ForeColor="#330099" BackColor="White"></ItemStyle>
                        <HeaderStyle Font-Bold="True" ForeColor="#FFFFCC" BackColor="#990000"></HeaderStyle>
                        <FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle>
                            <asp:TemplateColumn HeaderText="Id No">
                                    <asp:Label ID="IdNo">
                                        <%# DataBinder.Eval(Container.DataItem,"IdNo") %>
                            <asp:BoundColumn DataField="SName" HeaderText="Name"></asp:BoundColumn> <asp:BoundColumn DataField="FName" HeaderText="FName"></asp:BoundColumn> <asp:BoundColumn DataField="MName" HeaderText="MName"></asp:BoundColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" HeaderText="Edit" CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
<PagerStyle HorizontalAlign="Center" ForeColor="#330099" BackColor="#FFFFCC" Mode="NumericPages"></PagerStyle>

Now, In UpdateCommand event, I wrote these lines,

mycommand.Parameters["@IdNo"].Value = ((Label)DataGrid1.SelectedItem.Cells[0].FindControl("IdNo")).Text;
            mycommand.Parameters["@IdNo"].Value = "S0002"; //e.Item.Cells[0].Text;
            mycommand.Parameters["@SName"].Value=((TextBox)e.Item.Cells[1].Controls[0]).Text ;
            mycommand.Parameters["@FName"].Value=((TextBox)e.Item.Cells[2].Controls[0]).Text ;

First statement gave an error, while other two statements run successfully. Can anyone tell me, how to retrieve values from the template column(Keep in mind, I dont want to edit that column). Thanks,

Gaurav Jain
Old December 9th, 2006, 03:02 AM
Authorized User
Join Date: Sep 2006
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts

If u dont want to edit the column.then go for edit columns form.and make readonly property to true.

To get the reference of the template column use

control-type varname = (control-type)e.findcontrol("id of control);

Label mylabel =(label)e.findcontrol("LabelID");

Old December 9th, 2006, 04:33 AM
Friend of Wrox
Join Date: Feb 2006
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to gaurav_jain2403

Thank you for your help. The problem has been sorted out.

Similar Threads
Thread Thread Starter Forum Replies Last Post
Editing Datagrid toddw607 ASP.NET 2.0 Basics 5 April 26th, 2007 03:06 PM
Editing in DataGrid abdul_owiusa ASP.NET 1.0 and 1.1 Professional 0 May 1st, 2006 07:56 AM
Problem with Datagrid Editing pramesh_it ASP.NET 1.0 and 1.1 Basics 0 April 17th, 2006 09:58 AM
ASP(C#) : datagrid editing - alert problem shazia1 VS.NET 2002/2003 0 July 4th, 2005 03:34 AM
Multiplerecord editing in Datagrid vids ASP.NET 1.x and 2.0 Application Design 0 March 10th, 2005 11:41 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.