I do have a Problem concernig TemplateFields in a Gridview Control.
As EditItem Control I use a Dropdown Field. Depending on the Value of the Dropdown I´d like to change the Backround Colour of another Cell in the same Row.
At first I set the Row in Edit mode. Then I change the Value of the Dropdown an leave the Edit-Mode. I´ve tried several Events to start the change of the colour. For example the RowUpdating Event. But it alway occurs the same error. "NullReferenceExeption".
This is my code:
Dim aDropdown As New DropDownList
Dim aValue As String
aDropdown = GridView1.Rows(1).Cells(3).FindControl("DropDownList1")
aValue = aDropdown.Text
In Debug Mode aDropdown.Text shows the correct Value. I don´t understand what causes this error.
Can anyone of you please help me out? Thanks a lot in advance for your help!
Thanks alot. This Works. But I still have a Problem with the colours of the raws. At wich point can I change the colours of the gridview after editing a row? In the beginning I use the Page_load Event to change the colours. But after editing a row this event
doesn´t work anymore. Which is the correct event to choose?
Thanks a lot in advance for your answers and have a nice Weekend!
stumpi_8
0 Points
3 Posts
Problem with TemplateField in Gridview Control
Jan 10, 2013 10:47 AM|LINK
Hello,
I do have a Problem concernig TemplateFields in a Gridview Control.
As EditItem Control I use a Dropdown Field. Depending on the Value of the Dropdown I´d like to change the Backround Colour of another Cell in the same Row.
At first I set the Row in Edit mode. Then I change the Value of the Dropdown an leave the Edit-Mode. I´ve tried several Events to start the change of the colour. For example the RowUpdating Event. But it alway occurs the same error. "NullReferenceExeption".
This is my code:
Dim aDropdown As New DropDownList
Dim aValue As String
aDropdown = GridView1.Rows(1).Cells(3).FindControl("DropDownList1")
aValue = aDropdown.Text
In Debug Mode aDropdown.Text shows the correct Value. I don´t understand what causes this error.
Can anyone of you please help me out? Thanks a lot in advance for your help!
Greetz Stumpi
sukumarraju
All-Star
16983 Points
3000 Posts
Re: Problem with TemplateField in Gridview Control
Jan 10, 2013 10:54 AM|LINK
http://weblogs.asp.net/sukumarraju/archive/2009/12/23/populating-drop-down-list-selected-item-while-detailsview-in-edit-mode.aspx
Application Architecture Guide 2.0
My Blog
Twitter
oned_gk
All-Star
31655 Points
6470 Posts
Re: Problem with TemplateField in Gridview Control
Jan 10, 2013 10:54 AM|LINK
stumpi_8
0 Points
3 Posts
Re: Problem with TemplateField in Gridview Control
Jan 11, 2013 09:52 AM|LINK
Thanks alot. This Works. But I still have a Problem with the colours of the raws. At wich point can I change the colours of the gridview after editing a row? In the beginning I use the Page_load Event to change the colours. But after editing a row this event doesn´t work anymore. Which is the correct event to choose?
Thanks a lot in advance for your answers and have a nice Weekend!
Greetz Stumpi
oned_gk
All-Star
31655 Points
6470 Posts
Re: Problem with TemplateField in Gridview Control
Jan 11, 2013 10:51 AM|LINK
Change the color using rowdatabound event
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { } }