Enable Radiobutton in Gridview that has Alternate rows when edit button is clicked, using GridView.RowCreated

OK I have a gridview that has alternate rows enabled to make it look pretty :) I also have Radiobuttons in an ItemTemplate that are disabled (from editing) on the load of the gridview.  What I want to do is when I click Edit I want the radiobuttons enabled.  Well I got that part down accept every other will not enable the radio buttons.  I know I have to check the status of the row to see if it an alternate row but how would I then enable the controls on that row for edit.  Here is my code I have been playing with.   any suggestion would be great...

 

1    <script runAt="server">   
2           Sub methodname1(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs)
3               Dim row As GridViewRow = GridView1.Rows(e.NewEditIndex)
4                         
5               If row.RowState = (DataControlRowState.Edit) Then
6                   GridView1.SelectedIndex = e.NewEditIndex
7               End If
8               
9           
10          End Sub
11          Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles GridView1.RowCreated
12              
13              Select Case e.Row.RowState
14                  Case DataControlRowState.Alternate
15                      If e.Row.RowState = DataControlRowState.Selected Then
16                          DirectCast(e.Row.FindControl("RowSelector"), RadioButton).Enabled = True
17                          DirectCast(e.Row.FindControl("RowSelector1"), RadioButton).Enabled = True
18                          DirectCast(e.Row.FindControl("RowSelector2"), RadioButton).Enabled = True
19                          DirectCast(e.Row.FindControl("RowSelector3"), RadioButton).Enabled = True
20                      End If
21                  Case DataControlRowState.Edit
22                      DirectCast(e.Row.FindControl("RowSelector"), RadioButton).Enabled = True
23                      DirectCast(e.Row.FindControl("RowSelector1"), RadioButton).Enabled = True
24                      DirectCast(e.Row.FindControl("RowSelector2"), RadioButton).Enabled = True
25                      DirectCast(e.Row.FindControl("RowSelector3"), RadioButton).Enabled = True
26              End Select
27              
28              
29          End Sub
30          </script>
31   
32     <asp:TemplateField HeaderText="Private" HeaderStyle-ForeColor="white" >
33               <ItemTemplate >
34                   <asp:RadioButton ID="RowSelector2" runat="server" 
35                       GroupName="SuppliersGroup2"  Checked='<%# DataBinder.Eval(Container.DataItem, "PrivateIP")%>' Enabled="false"  />
36                       
37               </ItemTemplate>
38           </asp:TemplateField>
39            <asp:TemplateField HeaderText="Public" HeaderStyle-ForeColor="white">
40               <ItemTemplate>
41                   <asp:RadioButton ID="RowSelector3" runat="server" 
42                       GroupName="SuppliersGroup2" Checked='<%# DataBinder.Eval(Container.DataItem, "PublicIP")%>' Enabled="false" />
43                       
44               </ItemTemplate>
45           </asp:TemplateField>
  
0
tmacpherson
4/12/2007 4:54:52 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

5 Replies
1475 Views

Similar Articles

[PageSpeed] 40
Get it on Google Play
Get it on Apple App Store

0
Liming
4/12/2007 6:21:42 PM

Thanks but, Normal doesn't work because I need to check the Alternate rows.  if  I Comment out the if statement then every other row is enabled on load of grid (which I dont want) because the e.Row.RowState is set to Alternate the if statement in the first case to check if I clicked edit on an Alternating row never gets hit. I guess what I need to know is how do I enable the radio button after I click edit on an Alternate Row.

The second case works fine for the  even rows 1, 3 , 5 but not for the odd rows 2 , 4, 6 afer I click edit.. So someone on this site suggested I check the Alternate rows which seems to be what I need to do but I just cant get it...  

 

One would think this is easy "Click Edit and the Row is in edit mode and the radiobuttons get enabled."  Great for even rows but not odd rows,  this is crazy... 

 

 

1    Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles GridView1.RowCreated 
2
3 Select Case e.Row.RowState
4 Case DataControlRowState.Alternate
5 'If e.Row.RowState = DataControlRowState.Edit Then 6 DirectCast(e.Row.FindControl("RowSelector"), RadioButton).Enabled = True
7 DirectCast
(e.Row.FindControl("RowSelector1"), RadioButton).Enabled = True
8 DirectCast
(e.Row.FindControl("RowSelector2"), RadioButton).Enabled = True
9 DirectCast
(e.Row.FindControl("RowSelector3"), RadioButton).Enabled = True 10 ' End If 11
12 Case DataControlRowState.Edit
13 DirectCast(e.Row.FindControl("RowSelector"), RadioButton).Enabled = True
14 DirectCast
(e.Row.FindControl("RowSelector1"), RadioButton).Enabled = True
15 DirectCast
(e.Row.FindControl("RowSelector2"), RadioButton).Enabled = True
16 DirectCast
(e.Row.FindControl("RowSelector3"), RadioButton).Enabled = True
17 End Select
18
19
20 End Sub
  
0
tmacpherson
4/12/2007 11:52:35 PM
Nobody has an answer?  Surprise  Oh well I keep looking... 
0
tmacpherson
4/13/2007 2:34:01 PM

Hi:

  You can also do your work in RowCommand:

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Edit")
        {
            Response.Write(e.CommandArgument);

           //Find your control and enable it.
        }
    }

e.CommandArgument shows the rowindex from which you can know which row is in edit mode and find control in it.

Regards


Sincerely,
Allen Chen
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Allen
4/17/2007 7:38:00 AM

Hi,

I figured it out. For some reason Visual Studio can't handle all rowstates. The options you have are Alternate(1), Edit(4), Insert(8), Normal(0) and Selected(2). When you get your error your rowstate is 5!!

My solution to this problem is to manually check for e.Row.RowState = 5. In your case you have to add a case:

Case e.Row.RowState = 5
DirectCast(e.Row.FindControl("RowSelector"), RadioButton).Enabled = True
DirectCast
(e.Row.FindControl("RowSelector1"), RadioButton).Enabled = True
DirectCast
(e.Row.FindControl("RowSelector2"), RadioButton).Enabled = True
DirectCast
(e.Row.FindControl("RowSelector3"), RadioButton).Enabled = True

That should do it!

0
Mikael
4/25/2007 8:51:40 AM
Reply:

Similar Artilces:

Add new controls to a gridview row; when editing that row using the edit row feature in the gridview control.
Hi all  I have a questions that looks hard / complex to me, and i know you can help me in this. Q {  I have row in a Gridview and i have an edit option to it. I press the edit button, to edit the values in that row and update data all the way back to the database. Now when i press the edit button, i want a drop down list to be displayed that contain values for a particular field in my grid view. (for now only plain text boxes appear.) } I hope you understand my question, all i need to do is replace the text box controls with a dropdown list when i am editing a row in ...

using javascript getting value from textbox when edit button is clicked and both controls are present in gridview control
Hi All using javascript I want to get value  from textbox when edit button is clicked and both controls that is texbox and button are present in gridview control .Alok Hi aloksinha83, Please see this post: http://forums.asp.net/t/1069245.aspx Thanks,Qin Dian TangMicrosoft Online Community SupportPlease remember to mark the replies as answers if they help and unmark them if they provide no help....

Using INNER JOIN for fields in GridView control--Enable editing breaks GridView
Visual Studio 2005 used for everything below:2 tables created--Physician and PracticePhysician has a field named practiceID (int) which should act as foreign key to Practive.id (both type int, BUT NO relationships created)Dragged Physician table onto new .aspx pageSQL statement: SELECT Physician.id, Physician.lname, Physician.fname, Physician.mname, Physician.title, Physician.phone, Physician.address1, Physician.address2, Physician.city, Physician.state, Physician.zip, Practice.name FROM Physician INNER JOIN Practice ON Physician.practiceID = Practice.id ORDER BY Physician.lname, Physician.f...

Urgent:How to Add Row with Control(RadioButton or CheckBox) to GridView in button Click
 Hi all,I have a DropDown in Page having values "Single" and "Multiple" .And one button outsidethe gridView.When i click on button should add one row to Gridview with RadioButton if DropDown selected is "Single"or CheckBox if  DropDown selected is "Multiple". How to Achieve this, help me urgent  Plz.From Ravi.    hiplease go here.Hope this wil help youhttp://www.codeproject.com/KB/miscctrl/Dynamic_Control.aspx  Warm Regards.Please don't forget to click "Mark as Answer" on the post that helped you....

How to find a outer gridview row when a button in inner gridview row is clicked
Hi, I have a gridview within a gridview. In the inner gridview, I have a column of imagebuttons. I cannot figure out how to find out the row of the outer gridview when I click on the imagebutton in the inner gridview. I modifies the code below to get rid of some of the unnecessary stuff. <asp:GridView ID="SitePrepMainGV" runat="server" DataKeyNames="SitePrepItemID" DataSourceID="SitePrepMasterDS" OnRowDataBound="SitePrepMainGV_RowDataBound" OnRowEditing="SitePrepMainGV_RowEditing" OnRowCreated="SitePrepMainGV_RowCreated"> <Columns> <asp:BoundField DataField="S...

Iwant to select a row and column in gridview with select radiobutton. but No checked change event.below put a button .if click that button to seleced row values will select
I want to select a row and column in gridview using radiobutton in gridview . if which radio button is select that row will select and i want that row column values in outside individual textboxes of next page.  but in that only single radiobutton will select and no post back="true" bcz iam not using checked change property. i inserted button below gridview. if i click the that selected row and columns values are stored into textboxes of next page im using this code .but im getting one column in that row. but i want all columns in that selected row so plz repla...

Trying to use the FAQ " Sorting and paging in the GridView control when not using data source controls "Sorting and paging in the GridView control when not using..."
and I am not getting the results I had hoped for.  I keep getting a "Compiler Error Message: CS0123: No overload for 'AdhocJobGridView_PageIndexChanged' matches delegate 'System.EventHandler'".   Here is my event handling... protected void AdhocJobGridView_PageIndexChanged(object sender, GridViewPageEventArgs e){ try { AdhocJobGridView.DataSource = wsBaseInfoArray; AdhocJobGridView.PageIndex = e.NewPageIndex; AdhocJobGridView.DataBind(); }catch (Exception ex) {throw ex; }   Here is my aspx... <asp:GridView ID="AdhocJobGridView...

Gridview: Click edit button causes my Gridview to disappear.
When I use the following code, and click the "Edit" button for one of my rows, the entire Gridview dissapears on postback... Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Page.IsPostBack = False Then MainCats.AutoGenerateColumns = True MainCats.AutoGenerateEditButton = True MainCats.DataSource = MainCategory.FetchByParameter(MainCategory.Columns.Status, Comparison.Like, "ACTV") MainCats.DataBind() End If End Sub Protected Sub MainCats_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridVie...

I want to select a row and column in gridview using radiobutton in gridview
I want to select a row and column in gridview using radiobutton in gridview . if which radio button is select that row will select and i want that row column values in outside individual textboxes of next page.  but in that only single radiobutton will select and no post back="true" bcz iam not using checked change property. i inserted button below gridview. if i click the that selected row and columns values are stored into textboxes of next page im using this code .but im getting one column in that row. but i want all columns in that selected row so plz repla...

how to place a selected row from a gridview into another gridview by clicking a button
hi, In my application  i have binded the data from data base table to a grid view. my database table attributes are prodid,prodname ,price and qty. my grid view columns includes qty,prodname,price.i placed checkbox into my gridview and i placed a textboxes in the last column for placing required  qty from the available qty.after clicking on a checkbox of a perticular row  that selected row should be placed into another grid view by clicking on a submit button. the second gridview columns are serial no,prodname,qty(user required qty ), total price. in the last row of grid...

Can I populate a Gridview outside of the Gridview using my own edit controls ?
I want to be able to populate a GridView control through some edit controls that willbe displayed above my GridView control. Is their a way to do this without using a DetailsView control ? (Refer to the following article) http://www.dotnetbips.com/articles/c1e0ca90-5f5d-47aa-a739-492b562e810a.aspx Or can I have my own edit controls seperately from the GridView control? Actually, all you need to do is to put some textboxes and button. Than on button click insert that data in database and bind data to your gridviewagain. __Please mark post as answer if it helps, if not come back and a...

How to dynamically enable Edit Button in Gridview Row
Hi there. I am having difficulty, trying to dynamically enable / disable the edit button or edit CommandField depending on the True/False value of a field in the gridview. I have been trying to write code in the GridView_RowDataBound event, but I can't seem to get this to work. Any suggestions appreciated.   This is an example of what I have tried...  Protected Sub StocktakeGridView_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles StocktakeGridView.RowDataBound Dim Postedlabel As Label = CType(StocktakeGridView.Find...

GridView, Edit Row, user control button
I succesfully put a custom control inside a placeholder inside a cell when editing a row but when i click on a button or do anything which causes a postback the control disappears.protected void DropDownList1_OnSelectedIndexChanged(object sender, EventArgs e) { GridViewRow editrow = GridView1.Rows[GridView1.EditIndex]; PlaceHolder p1 = (PlaceHolder)editrow.FindControl("OptionsPlaceHolder"); DropDownList ddl1 = (DropDownList)sender; if (ddl1.SelectedItem.Text == "Combo") { Control uc1 = LoadControl("~/Us...

I want to select a row and column in gridview using radiobutton in gridview #2
I want to select a row and column in gridview using radiobutton in gridview . if which radio button is select that row will select and i want that row column values in outside individual textboxes of next page.  but in that only single radiobutton will select and no post back="true" bcz iam not using checked change property. i inserted button below gridview. if i click the that selected row and columns values are stored into textboxes of next page im using this code .but im getting one column in that row. but i want all columns in that selected row so plz repla...

Web resources about - Enable Radiobutton in Gridview that has Alternate rows when edit button is clicked, using GridView.RowCreated - asp.net.presentation-controls

'android-widget' tag wiki - Stack Overflow
Q&A for professional and enthusiast programmers

dBase - Wikipedia, the free encyclopedia
dBase II was the first widely used database management system (DBMS) for microcomputers . It is a relational database management system. It was ...

Perl/Tk Menus: Past, Present and Future - The Perl Journal, Summer 1999
Whether they drop down as rectangles or pop up as pies, menus are widgets that managebundles of related information. Menus are pervasive, appearing ...

Index - 2,000 Things You Should Know About WPF
Below is a list of all posts created so far for the 2,000 Things You Should Know About WPF blog. Total number of posts = 1,077 Animation #7 - ...

Moonify UI - 365psd
Join our growing community of Photoshop users. Sign Up or Log In 365psd Download a free psd every day. Collections Contributors Premium Files ...

Learning Mobile Development - Android and iOS Lessons For Beginners
... Android and iOS Lessons For Beginners Menu Skip to content Home Android Tutorials IOS Tutorials Contact us Search for: Customize RadioButton ...

Basic4android (Basic for Android) - Android programming with Gui designer
Basic4android (Basic for Android) is a simple and powerful development environment for developers of Android applications.

Bravenet Webmaster Resource Center - Scripts, sounds, art and more
Cheap web hosting and free web tools. Build your website with our easy webpage builder, web tools, web services, and free website content.

Gchat - Home
Gchat - is easy to use program, suitable for communicating with friends. This non-commercial program that you can change it as you like. Program ...

Microsoft readies Silverlight 2 beta
Featured in Version 2 is a cross-platform, cross-browser version of the .Net Framework, a Microsoft official said.

Resources last updated: 12/1/2015 10:55:25 PM