473,394 Members | 1,878 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

GridView SelectedRow

Hi,

I've a radiobutton in my gridview and I want to dislpay the value in a cell
of the selected value on the RadioButton click using this code :
TextBox.Text = MyGridView.SelectedRow.Cells[1].ToString();
but it's giving me this error:
"Object reference not set to an instance of an object"
how can I fix it
Thanks

Dec 5 '06 #1
7 7726
Badis maybe try posting some more snippet code
Patrick

"Badis" <Ba***@discussions.microsoft.comwrote in message
news:E8**********************************@microsof t.com...
Hi,

I've a radiobutton in my gridview and I want to dislpay the value in a
cell
of the selected value on the RadioButton click using this code :
TextBox.Text = MyGridView.SelectedRow.Cells[1].ToString();
but it's giving me this error:
"Object reference not set to an instance of an object"
how can I fix it
Thanks

Dec 5 '06 #2
I'm doing it in a CheckedChanged event of a RadioButton in a TemplateField of
MyGridView

protected void MyRadioButton_CheckedChanged(object sender, EventArgs e)
{
TextBox.Text = MyGridView.SelectedRow.Cells[1].ToString();
}

"Patrick.O.Ige" wrote:
Badis maybe try posting some more snippet code
Patrick

"Badis" <Ba***@discussions.microsoft.comwrote in message
news:E8**********************************@microsof t.com...
Hi,

I've a radiobutton in my gridview and I want to dislpay the value in a
cell
of the selected value on the RadioButton click using this code :
TextBox.Text = MyGridView.SelectedRow.Cells[1].ToString();
but it's giving me this error:
"Object reference not set to an instance of an object"
how can I fix it
Thanks


Dec 6 '06 #3
Badis where is the textbox?
Post your aspx page etc..
Elaborate more
Patrick

"Badis" <Ba***@discussions.microsoft.comwrote in message
news:68**********************************@microsof t.com...
I'm doing it in a CheckedChanged event of a RadioButton in a TemplateField
of
MyGridView

protected void MyRadioButton_CheckedChanged(object sender, EventArgs e)
{
TextBox.Text = MyGridView.SelectedRow.Cells[1].ToString();
}

"Patrick.O.Ige" wrote:
Badis maybe try posting some more snippet code
Patrick

"Badis" <Ba***@discussions.microsoft.comwrote in message
news:E8**********************************@microsof t.com...
Hi,
>
I've a radiobutton in my gridview and I want to dislpay the value in a
cell
of the selected value on the RadioButton click using this code :
TextBox.Text = MyGridView.SelectedRow.Cells[1].ToString();
but it's giving me this error:
"Object reference not set to an instance of an object"
how can I fix it
>
>
Thanks
>

Dec 7 '06 #4
Also try looking at:
http://msdn2.microsoft.com/en-us/lib...lectedrow.aspx
Hope that helps
Patrick
"Badis" <Ba***@discussions.microsoft.comwrote in message
news:68**********************************@microsof t.com...
I'm doing it in a CheckedChanged event of a RadioButton in a TemplateField
of
MyGridView

protected void MyRadioButton_CheckedChanged(object sender, EventArgs e)
{
TextBox.Text = MyGridView.SelectedRow.Cells[1].ToString();
}

"Patrick.O.Ige" wrote:
Badis maybe try posting some more snippet code
Patrick

"Badis" <Ba***@discussions.microsoft.comwrote in message
news:E8**********************************@microsof t.com...
Hi,
>
I've a radiobutton in my gridview and I want to dislpay the value in a
cell
of the selected value on the RadioButton click using this code :
TextBox.Text = MyGridView.SelectedRow.Cells[1].ToString();
but it's giving me this error:
"Object reference not set to an instance of an object"
how can I fix it
>
>
Thanks
>

Dec 7 '06 #5
It doesn't mater because even if I do this:
string MyString = MyGridView.SelectedRow.Cells[1].ToString();
it will give me the same error!!! and it looks like in the click event of
the RadioButton the "SelectedRow" is not set or equal to null !!!?

"Patrick.O.Ige" wrote:
Badis where is the textbox?
Post your aspx page etc..
Elaborate more
Patrick

"Badis" <Ba***@discussions.microsoft.comwrote in message
news:68**********************************@microsof t.com...
I'm doing it in a CheckedChanged event of a RadioButton in a TemplateField
of
MyGridView

protected void MyRadioButton_CheckedChanged(object sender, EventArgs e)
{
TextBox.Text = MyGridView.SelectedRow.Cells[1].ToString();
}

"Patrick.O.Ige" wrote:
Badis maybe try posting some more snippet code
Patrick
>
"Badis" <Ba***@discussions.microsoft.comwrote in message
news:E8**********************************@microsof t.com...
Hi,

I've a radiobutton in my gridview and I want to dislpay the value in a
cell
of the selected value on the RadioButton click using this code :
TextBox.Text = MyGridView.SelectedRow.Cells[1].ToString();
but it's giving me this error:
"Object reference not set to an instance of an object"
how can I fix it


Thanks

>
>
>


Dec 7 '06 #6
Badis have you looked at the msdn link i posted earlier?
Patrick

"Badis" <Ba***@discussions.microsoft.comwrote in message
news:32**********************************@microsof t.com...
It doesn't mater because even if I do this:
string MyString = MyGridView.SelectedRow.Cells[1].ToString();
it will give me the same error!!! and it looks like in the click event of
the RadioButton the "SelectedRow" is not set or equal to null !!!?

"Patrick.O.Ige" wrote:
Badis where is the textbox?
Post your aspx page etc..
Elaborate more
Patrick

"Badis" <Ba***@discussions.microsoft.comwrote in message
news:68**********************************@microsof t.com...
I'm doing it in a CheckedChanged event of a RadioButton in a
TemplateField
of
MyGridView
>
protected void MyRadioButton_CheckedChanged(object sender, EventArgs
e)
{
TextBox.Text = MyGridView.SelectedRow.Cells[1].ToString();
}
>
"Patrick.O.Ige" wrote:
>
Badis maybe try posting some more snippet code
Patrick

"Badis" <Ba***@discussions.microsoft.comwrote in message
news:E8**********************************@microsof t.com...
Hi,
>
I've a radiobutton in my gridview and I want to dislpay the value
in a
cell
of the selected value on the RadioButton click using this code :
TextBox.Text = MyGridView.SelectedRow.Cells[1].ToString();
but it's giving me this error:
"Object reference not set to an instance of an object"
how can I fix it
>
>
Thanks
>


Dec 7 '06 #7
Badis wrote:
I'm doing it in a CheckedChanged event of a RadioButton in a TemplateField of
MyGridView

protected void MyRadioButton_CheckedChanged(object sender, EventArgs e)
{
TextBox.Text = MyGridView.SelectedRow.Cells[1].ToString();
}
Hi,

You need to make sure that the SelectedIndex property is not set to -1
when you try to access the SelectedRow.

There has to be a command type control somewhere in your template (e.g.
button or LinkButton) that generates a postback event and is assigned
the string value "Select" to its CommandName property (a RadioButton
control can't be used for this). That will raise a SelectIndexChanged
event and the SelectedRow property will then point to an actual row of
the grid.

HTH

Dec 7 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: mosscliffe | last post by:
I have a gridview and in the GridView1_SelectedIndexChanged routine I am attempting to get at the data in the row I have done it successfully with cells 'Access the contents of a field in a...
1
by: Dot Net Daddy | last post by:
Hello, I have a question about assigning a value in the selectedRow of a gridview to another variables. How can I do that? I am trying the following but it wont work;
4
by: AG | last post by:
I have a asp.net 2.0 gridview control with select, edit, delete buttons enabled and set to image button type to display my images. Is there any way to access the selectedimageurl property at run...
1
by: jobs | last post by:
Given the Gridview below: When I select the button "Rate" and fall into this code. How can I reference "carriercode" and others . Apparently selecting the button does not select the row. I've...
1
by: moni | last post by:
Hi, I was hoping to know how I could get the text value of a gridview row. My code is this way: <asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False"...
14
by: Mike | last post by:
I have a gridview that has a button in the last cell of each row. I want to get the text from cell 1 for that row the button was clicked on. So if my gridview looks like this: N-12 BMW ...
0
by: Moneypenny | last post by:
Hi there, I have a Gridview control which has a dropdownlist in every row. The dropdowns are populated dynamically from a database (so the content is different in each row. There is also a select...
7
by: =?Utf-8?B?SnVsaWEgQg==?= | last post by:
Hi all, this is a second post, so apologies, but I never had an answer to my first post (several weeks ago) and I really need some help. I'm using a .Net 2.0 Gridview which is populated using an...
0
by: edurazee | last post by:
I am able to create BoundFields and Footer-rows dynamically like this in my GridView: protected void Page_Load(object sender, EventArgs e) { CreateGridView(); ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.