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
|