Thanks its working fine for single row where row id is 0, but i need to select individual rows every time why because dropdown is available in each row...
for example in my grid i have 10 rows when ever i select 1st row that first row textbox only become readonly...
shwetha.gadd...
Member
132 Points
65 Posts
set the readonly property to textbox in gridview using dropdownlist
May 07, 2012 12:22 PM|LINK
protected void Change(object sender, EventArgs e) { GridViewRow row = GridView1.SelectedRow; DropDownList dlMng = (DropDownList)sender; TextBox txtreason = (TextBox)GridView1.SelectedRow.FindControl("txtreason"); if (dlMng.SelectedIndex == 0) { txtreason.ReadOnly = true; } if (dlMng.SelectedIndex == 1) { txtreason.ReadOnly = false; } }This is my mycode:
In this code i had a error at this line:
TextBox txtreason = (TextBox)GridView1.SelectedRow.FindControl("txtreason");Object reference not set to an instance of an object.
any one pls help me...
C#.net
cninjas
Contributor
4868 Points
851 Posts
Re: set the readonly property to textbox in gridview using dropdownlist
May 07, 2012 12:29 PM|LINK
Hi
The findcontrol couldn't able to find the textbox. Do check whether you are getting Gridview.Selectedrow
It should return you GridViewDataRow
hope it helps, thanks.
Niranjan
shwetha.gadd...
Member
132 Points
65 Posts
Re: set the readonly property to textbox in gridview using dropdownlist
May 07, 2012 12:33 PM|LINK
I want to insert bulk from my grid view...
Now i deleted seletced row from my code now it shows the same error at 'txtreason'
there is any another way?
cninjas
Contributor
4868 Points
851 Posts
Re: set the readonly property to textbox in gridview using dropdownlist
May 08, 2012 04:21 AM|LINK
hi
Are you trying to get the single row? or you want to loop thru all the rows?
TextBox txtreason = (TextBox)GridView1.Rows[0].FindControl("txtreason");Try this....Please clarify whether the Dropdown will be avlb for each rows? or on the headerthanks.Niranjan
shwetha.gadd...
Member
132 Points
65 Posts
Re: set the readonly property to textbox in gridview using dropdownlist
May 08, 2012 04:38 AM|LINK
Thanks its working fine for single row where row id is 0, but i need to select individual rows every time why because dropdown is available in each row...
for example in my grid i have 10 rows when ever i select 1st row that first row textbox only become readonly...
pls help me for this...
cninjas
Contributor
4868 Points
851 Posts
Re: set the readonly property to textbox in gridview using dropdownlist
May 08, 2012 05:51 AM|LINK
hi
I think the onchange event is mapped to your dropdown selectedindex changed?
just include this line in the event
Niranjan
cninjas
Contributor
4868 Points
851 Posts
Re: set the readonly property to textbox in gridview using dropdownlist
May 08, 2012 05:54 AM|LINK
protected void Change(object sender, EventArgs e) { DropDownList ddl = (DropDownList)sender; GridViewRow row = (GridViewRow)ddl.Parent.Parent; int idx = row.RowIndex; DropDownList dlMng = (DropDownList)sender; TextBox txtreason = (TextBox)GridView1.Rows[idx].FindControl("txtreason"); if (dlMng.SelectedIndex == 0) { txtreason.ReadOnly = true; } if (dlMng.SelectedIndex == 1) { txtreason.ReadOnly = false; } }Niranjan
MahadTECH
Star
8976 Points
1659 Posts
Re: set the readonly property to textbox in gridview using dropdownlist
May 08, 2012 06:04 AM|LINK
Try this Code:
protected void Change(object sender, EventArgs e) { GridViewRow row = GridView1.SelectedRow; DropDownList dlMng = (DropDownList)sender; TextBox txtreason = (TextBox)GridView1.SelectedRow.FindControl("txtreason"); if (dlMng.SelectedItem = 0) // OR dlMng.SelectedValue = 0 { txtreason.ReadOnly = true; } if (dlMng.SelectedItem = 1) // OR dlMng.SelectedValue = 1 { txtreason.ReadOnly = false; } }Mahad Bin Mukhtar
Remember to Mark the replies as Answers
The easiest day was 'yesterday'.
MCP, MCSD
For .NET TECH Blog
shwetha.gadd...
Member
132 Points
65 Posts
Re: set the readonly property to textbox in gridview using dropdownlist
May 08, 2012 06:04 AM|LINK
Thank you....
Its working fine....
MahadTECH
Star
8976 Points
1659 Posts
Re: set the readonly property to textbox in gridview using dropdownlist
May 08, 2012 06:07 AM|LINK
Which Answer is working Fine? Mark As Answer!
Mahad Bin Mukhtar
Remember to Mark the replies as Answers
The easiest day was 'yesterday'.
MCP, MCSD
For .NET TECH Blog