473,386 Members | 1,819 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,386 software developers and data experts.

DataItem is NULL, problem

hi

asp.net 2.0

I have a GridView on a webpage. This GridView has a TemplateField which
again contain a LinkButton. When I click on that LinkButton I want some
action to take place on that row the LinkButton exists. When I click on the
LinkButton the lbCar_Command method is triggered. But in this line the
variable car gets a NULL value:
CarDetail car = (CarDetail)row.DataItem;
I thought DataItem existed for every row, as I'm using DataItem in the
RowDataBound

protected void gvwCars_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
CarDetail car = (CarDetail)e.Row.DataItem;
LinkButton button = (LinkButton)e.Row.FindControl("lbCar");
button.CommandArgument = e.Row.RowIndex.ToString();
}
}

protected void lbCar_Command(object sender, CommandEventArgs e)
{
int rowIndex = Int32.Parse(e.CommandArgument.ToString());
GridView grid = (GridView)LoginView1.FindControl("gvwCars");
GridViewRow row = grid.Rows[rowIndex];
CarDetail car = (CarDetail)row.DataItem;
}

(I don't want to create a separate field in the GridView with ButtonField
instead, as it will change the GUI of this GridView entirely, this GridView
have only one column but it's a TemplateField containing serveral controls
and divs)

Any suggestions?
Oct 13 '08 #1
1 1714
okay I've kind of solved this problem. I made a workaround the problem.
instead of having rownumber stored in commandargument, I instead placed a
primary key value. Anyway it's this id I need in that command...
Oct 13 '08 #2

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

Similar topics

3
by: DonRex | last post by:
Hello all! I couldn't find a web application-newsgroup for ASP.NET, so I'm sorry if this is the wrong forum! Synopsis: In my webform I have 3 nested repeaters: rpWeeks ----- rpTime
2
by: Tom Lee | last post by:
Hi all, I have the following problem and I cannot solve it. If anyone can help me solve this problem. I use the following code <%#DataBinder.Eval(Container.DataItem, "Property")%> to display...
2
by: Joel Lyons | last post by:
The help pages make it look like the DataGridItem.DataItem property would return a row from the bound table. Like so: //(during setup) myGrid.DataSource = myDataset.MyTable; myGrid.DataBind();...
1
by: jw56578 | last post by:
What is the explanation for the following. if i do: reapeter1.datasource = somedatasource repeater1.databind() foreach(RepeaterItem ri in repeater1.Items) { object o = ri.DataItem; }
1
by: Adam Knight | last post by:
Hi all, A quick question on data item availability? See the function below. Upon clicking an button the following function is executed. My problem is, whenever the DataItem property is access...
7
by: Mirek Endys | last post by:
Hello, the problem I have now, is: Im binding generic collection based on List<iDB2SQLTransferItem> // iDB2SQLTransferItem is my class // into WebCOntrol DataList. But the DataItem of the...
2
by: ibiza | last post by:
Hi all, I have a simple scenario where I simply bien a repeater to a datasource. Here's my repeater definition : <asp:Repeater id="rTitles" runat="server" EnableViewState="false"...
15
by: Laser Lu | last post by:
Hi, all, I was tangled by the DataGridItem.DataItem property. I tried to invoke that property to get and display the contents that was bound to the currently selected row. However, an exception...
1
by: Bresco | last post by:
I'm using ObjectDatasource in combination with a Formview. The ObjectDatasource is connected to a FormView. I have a business object property which I can't update through the normal binding...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.