DataGrid
-
hi all, right now i am trying to work on Datagrid. 1.How do you apply specific formatting to the data inside the cells? and in my gird i am giving option to the user to modify the rows. before updating the data, just i want to check whether the user modified any data?? 2.How do you check whether the row data has been changed? 3.How do you customize the column content inside the datagrid? just we need to make the column as Item template?? or do need to write any code? thanks, Rahi
If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
-
hi all, right now i am trying to work on Datagrid. 1.How do you apply specific formatting to the data inside the cells? and in my gird i am giving option to the user to modify the rows. before updating the data, just i want to check whether the user modified any data?? 2.How do you check whether the row data has been changed? 3.How do you customize the column content inside the datagrid? just we need to make the column as Item template?? or do need to write any code? thanks, Rahi
If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
Hi Rahi, I am not sure but this will give you some idea! 1.You can apply specific formatting to the data inside the cells using DataGrid rightclick>PropertyBuilder>Formatting>Items 2.You can add a hidden grid column say "Modified" and it's default value is "N".Now in DataGrid1_ItemDataBound you need to add clientside ontextchage eventhandler for desired cells Serverside:- private void DataGrid1_ItemDataBound(object sender,System.Web.UI.WebControls.DataGridItemEventArgs e) { //This code is for assigning userdefined Id's for rows and columns e.Item.ID = "Row" + i++; for(int j=0;j<7;j++) e.Item.Cells[j].ID="Column"+j; //Here you need to pass the rowid e.Item.Cells[j].Attributes.Add("ontextchanged","modif('"+ e.Item.ID + " ')" ); } JavaScript:- function modif(RowId) { //This line will set the value to 'Y' when the row is modified document.getElementById('DataGrid1_'+RowId +'_Modified').innerText="Y" } 3.When you give the provision for editing the rows you can also validate the datagrid. private void Page_Load(object sender, System.EventArgs e) { da.Fill(dataSet11,"employee"); DataGrid1.DataBind(); Button1.Attributes.Add("onclick","return validate()"); } JavaScript:- function validate() { if(document.getElementById('DataGrid1_Row0_Column1').innerText="") alert('Please enter '); //Like this you can set the values to the grid document.getElementById('DataGrid1_Row0_Column1').innerText="kkkk"; alert(document.getElementById('DataGrid1_Row0_Column1').innerText); return false; }
Kiran Kumar.CH (MCP)