-
DataGrid formatting not working
Hi all! I have the following three questions, the answers to which still elude me. Any help would be highly appreciated:
1. I have a DataGrid (firstly, with a disabled viewstate and secondly, the entire DataGrid is editable, with a single Button at the bottom instead of editing data one row at a time). This DataGrid displays rows from a table A in an Oracle database. When the Submit button is clicked, it will result in two actions:
(a) A csv file will get downloaded to the user's computer which will contain all the rows of the grid and at the same time these rows will be inserted into another table B.
(b) The entire grid will be recreated and reloaded. During the reload all the original rows will be loaded with the difference that since they have been downloaded to the user's computer, they will be colored differently(For this, a query checks the table B). I have used OnItemDataBound event for this.
The problem is in step (b) during the reloading of data from the datasource. Although the code does reach the lines which color the rows (in OnItemDataBound event handler) and they get executed, yet when the page gets displayed finally, the rows appear with the original color. The change comes into effect only if I refresh the page through the browser.
Why is this happening and how can I make sure that the rows do get colored when the datagrid is reloading?
2. This is related to step 1. I want the background of the rows to get colored. For this I use the statement:
Code:
e.Item.BackColor = Color.DodgerBlue;
where e is of type DataGridItemEventArgs. Yet this does not work. But strangely, the forecolor does change using :
Code:
e.Item.ForeColor = Color.DodgerBlue;
How can I change the BackColor?
3. Can I disable a custom GridRadioButtonListColumn inside a DataGrid so that selected radio is visible to the user but cannot be deselected/modified?
Thanx.
The best way to predict the future is to create it
~~~~~~~~~~~~~~~~~~  ~~~~~~~~~~~~~~~~~~
-
the radio button issue
if u have the radio button column in the grid as a template column, you can reach the properties of the radio button list through--->Edit template column--.
Right click on the grid-->Edit template .then click on the radion button..go to the properties window and set Enabled=false.there u'll have a disabled radio button list.
-
Hi persian_celina,
Thx for ur reply. But can this be done programmatically?
The best way to predict the future is to create it
~~~~~~~~~~~~~~~~~~  ~~~~~~~~~~~~~~~~~~
-
This answers your 2nd question. In your Item_databound event, declare a new datagriditem and convert that item to the index of the item in the datagrid. Then change the background color of the datagriditem. Also make sure you import the System.Drawing namespace. You may have to have viewstate enabled.
Here is a sample:
private void dgWhatever_ItemDatabound(Object sender, DatagridCommandEventArgs e)
{
DataGridItem dgItem;
dgItem = (DatagridItem)dgWhatever.Items(e.Item.ItemIndex);
//Add Database conditional statement here
dgItem.BackColor = Color.DodgerBlue;
}
-
Thanx sloc23 for taking out the time to read my query and also for the reply. I will try this out and let you know the result.
Does anybody have any ideas for part 1 of my post. The refreshing of the page is really bugging me.
The best way to predict the future is to create it
~~~~~~~~~~~~~~~~~~  ~~~~~~~~~~~~~~~~~~
-
Hi all,
My office has been relocated so I am back in business. So continuing with my post, as regards to point 3 (persian_celina, please note), my earlier code is now working fine i.e the radios are getting disabled. The code that I used was....
Code:
e.Item.Cells[2].Enabled = false;
So the question crops up, why was this not happening earlier. The answer is browser-incompatibility. This same code was not working in Netscape but it is working perfectly in IE. If you want to know why this was happening, then I am not the right person to answer coz I don't know. If anybody has the answer to that, he/she is welcome to post it.
Does anybody have the answer to part 1 of my original post?
Hi sloc23, I am so deep in the code with the datagrid now, that I cannot possibly enable the viewstate. Moreover, you are showing the use of "Items" as a function in the code that u sent, but I think it is a property of datagrid which does not take Itemindex as a parameter.
The best way to predict the future is to create it
~~~~~~~~~~~~~~~~~~  ~~~~~~~~~~~~~~~~~~
-
I am extremely sorry for "bumping" this thread, but I am at my wit's end now. I really have to complete this module but this problem is delaying the whole project.
Please, anybody, do reply if you have an answer.
The best way to predict the future is to create it
~~~~~~~~~~~~~~~~~~  ~~~~~~~~~~~~~~~~~~
-
hi there..about the first point...since u said u keep the selected rows in a B table,check out the number of times the page-load event is executed!...
Can i have a look at ur itemdatabound & page _ load event codes?
PS.have u checked !("ispostback" ) in the page_load event?
-
heyy
there's no need to that itemdatabound thing.
try to handle the grid reload and also the comparison between the griditems and the Table B rows (to find the repeated rows) + recoloring the found items All in the Click event of that submit button.
i tried it..it works..
for finding the due items it's easier to use "foreach":
private void Submit_Click(object sender, System.EventArgs e)
{
//Rebind the datagrid here...or let's say reload it (if necessary)b/c it works both way.
SqlDataAdapter da1=new SqlDataAdapter("select C.CmpCode,TB.* from Company C,TB",sqlConnection1);
DataSet ds1=new DataSet();
da1.Fill(ds1);
DataGrid1.DataSource=ds1;
DataGrid1.DataBind();
//Searching through the grid items+finding the ones present in Table B and changing their color settings
foreach (DataGridItem i in DataGrid1.Items)
{
if (i.Cells[0].Text=="103") //or anyother condition in comparison with Table B values
{
i.ForeColor=Color.Red;
i.BackColor=Color.CadetBlue;
}
}
}
-
HI persian_celina,
I am sincerely grateful to u for devoting your time in finding a solution to my problem.
I will try this out and let you know the results.
Thanx again
The best way to predict the future is to create it
~~~~~~~~~~~~~~~~~~  ~~~~~~~~~~~~~~~~~~
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks