Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > .NET 1.0 and Visual Studio.NET > .NET Framework 1.x
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
.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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 9th, 2006, 01:55 AM
Friend of Wrox
 
Join Date: Feb 2006
Location: noida, UP, India.
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>
                        <Columns>
                            <asp:TemplateColumn HeaderText="Id No">
                                <ItemTemplate>
                                    <asp:Label ID="IdNo">
                                        <%# DataBinder.Eval(Container.DataItem,"IdNo") %>
                                    </asp:Label>
                                </ItemTemplate>
                            </asp:TemplateColumn>
                            <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>
                    </asp:DataGrid>

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
__________________
Gaurav
Reply With Quote
  #2 (permalink)  
Old December 9th, 2006, 03:02 AM
Authorized User
 
Join Date: Sep 2006
Location: , , .
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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);

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

Reply With Quote
  #3 (permalink)  
Old December 9th, 2006, 04:33 AM
Friend of Wrox
 
Join Date: Feb 2006
Location: noida, UP, India.
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to gaurav_jain2403
Default

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 05:09 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.