In my datagrid i have 9 columns. In that 4 column should be noneditable. If i use the readonly property in the design mode. Always the column in noneditable. But for me when i click on the checkbox, if it is true then that particular 4 column should be noneditable . If the checkbox is false, all the 9 column should be editable. For me all the column editable is working fine. But i have problem with the column nonediting.
In the design page i wrote as:
<
asp:TemplateColumn HeaderText="IPAddress">In the edit command i wrote as below
((TextBox)e.Item.FindControl("txtaddress")).ReadOnly = true;
Please help me with this question.
Santhosh Kumar JayaramanPosted May 2, 2012, 7:22 AM
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="NoneditableFieldsinGrid._Default" %>
HeaderStyle-BorderColor="Black">
HeaderStyle-BorderStyle="Dashed" HeaderStyle-BorderColor="Black">
HeaderStyle-BorderStyle="Dashed" HeaderStyle-BorderColor="Black">
Santhosh Kumar JayaramanPosted Apr 30, 2012, 10:00 PM
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace NoneditableFieldsinGrid
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
List
new Student() { Name = "Jack", Age = 15, StudentId = 100 },
new Student() { Name = "Smith", Age = 15, StudentId = 101 },
new Student() { Name = "Smit", Age = 15, StudentId = 102 }
};
GridView_Classes.DataSource = Students;
GridView_Classes.DataBind();
}
protected void GridView_Classes_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex >= 0)
{
string chkClientId = e.Row.FindControl("CheckBox_Select").ClientID;
string txt2ClientId = e.Row.FindControl("TextBox_NonEditable").ClientID;
( (CheckBox)e.Row.FindControl("CheckBox_Select")).Attributes.Add("onclick", "javascript:checkitem(" + chkClientId + ","+ txt2ClientId + ");");
}
}
}
public class Student
{
public string Name { get; set; }
public int StudentId { get; set; }
public int? Age { get; set; }
}
}
Arthi DevPosted Apr 30, 2012, 7:01 PM
Thanks for the help. But sorry i Couldn't open the attachment. I need very urgent solution.
Santhosh Kumar JayaramanPosted Apr 30, 2012, 2:25 AM
-Santhosh