|
hi,
I am not sure you can cast e.Row.DataItem into a DataRowView because e.Row is a GridViewRow and not a DataRow, which is not exactly the same.
To access individual columns of a gridview row, I use the following (in RowDataBound event method):
GridViewRow row = e.Row;
TableCell tcell = row.Cells[0];
string temp = tcell.Text;
Hope this helps.
Talal
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
--Rich Cook
|
|
|
|
|
My problem is I want to access fist row and but first row is treated as header and last row is treated as footer.
Hence when I check below condition, It thows error.
if (e.Row.RowType == DataControlRowType.DataRow )
Pavas
|
|
|
|
|
Ok, if you're using the statement you wrote in the post, I believe it is normal that you get an "object not set" error.
You said that you use the following expression:
if (e.Row.RowType == DataControlRowType.DataRow) || (e.Row.RowType == DataControlRowType.Header)
This indicates that if the row is either a data row or a header do something. In case it is a header, there is no data in it and it might throw an error if you attempt to access something that is not there.
I have never used DataItem so I cannot tell you for sure but what I'm sure of is that I use the following and it works very well:
GridViewRow row = e.Row;
if (row.RowType == DataControlRowType.Header)
{
}
if (row.RowType == DataControlRowType.DataRow)
{
}
It could help if you post more code to see exactly what is written.
Talal
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
--Rich Cook
|
|
|
|
|
Yup I agree with you.
The code is as below:
if (e.Row.RowType == DataControlRowType.DataRow )
{
DataRowView rowView = (DataRowView)e.Row.DataItem;
string Code = rowView["CODE"].ToString();
}
Thie fist row doesn't match the condition as row type is DataControlRowType.Header.
But the first row has some data and i want the fist row shouldnt be a DataControlRowType.Header.
Does this helps you to solve the problem
Pavas
|
|
|
|
|
You can choose to remove the header from the GridView if you don't want it at all.
I have tried writing similar lines in my code. I didn't get any error with DataRowView rowView = (DataRowView)e.Row.DataItem . Now I'm thinking that maybe the data binding was not done properly for the GridView? If the data binding was not done, DataItem would be empty and the cast (DataRowView)e.Row.DataItem could thrown an error. I don't see what else could be wrong. Maybe someone can provide a fresh perspective.
Talal
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
--Rich Cook
|
|
|
|
|
I am not sure why this is happening...? Could some one help on this
Pavas
|
|
|
|
|
Hi guys how to creat note pad in runtime in asp.net plz give some sample code
Praveen Kumar.R
|
|
|
|
|
Your question is illogical. You can't create a notepad in ASP.NET, because you can't save files locally. You can trivially add a text control, and save the contents to the server, however. What do you mean by 'in runtime'. What is it you want to do ?
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Did U mean text editor ?
U should use javascript to ceate that.
www.fckeditor.net
Hope this will help U
Regard,
Edwin
|
|
|
|
|
hi,
below this is the code written in C#.net .i want the correspond vb.net code. thanks in advance...
" string distict = ((DropDownList)MyGridView.FooterRow.FindControl("ddlDistrict")).SelectedValue.ToString().Trim();"
where MyGrid=id of the gridview
ddlDistrict=id of the ddl which is taken in side the footer template of gridview
|
|
|
|
|
Please don't cross post.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
dim distict as string=ctype(MyGridView.FooterRow.FindControl("ddlDistrict"),DropDownList).SelectedValue.ToString().Trim()
Best regard
Pathan
---------------------------------------------------
|
|
|
|
|
Hi friends
I need validation expression string for 'XXX XXX' format
Thanks In advance
pathan
---------------------------------------------------
|
|
|
|
|
What do the X's mean ? you probably mean you need to build a regex ? Expresso is a great tool for that.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Use Regular Expression Validator.
\s{3} \s{4}
|
|
|
|
|
Thanks
Pathan
---------------------------------------------------
|
|
|
|
|
hi,
This is the regular expression for U.S Phone number(XXX-XXX-XXXX)
((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}
You can edit it and use it for your work accordingly..
SHWETA!!
|
|
|
|
|
Thanks
Pathan
---------------------------------------------------
|
|
|
|
|
Hi guys, iam using session in my project some session variables are interger some other string. when session expired i click next button they show error, so i want to validate when session is expired. so please give some ideas how to validate
Praveen Kumar.R
|
|
|
|
|
The best you can do is work out in your pages that it has timed out, and redirect to the login page.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Before getting the data from the Session first check is not null.
Parwej Ahamad
g.parwez@gmail.com
|
|
|
|
|
praveenkumar_mca wrote: so i want to validate when session is expired.
As Christian told you need to validate session existence on each page_load. It could be something like
if ( session["yoursessionvalue"] == null)
Response.Redirect("Loginpage");
|
|
|
|
|
Check the session value in page load. If it is null then redirect the login page showing the message that your session is time out.
|
|
|
|
|
Why is it that suddenly so many questions get the same answer given over and over again ?
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Respected Gurus
I have to export a datagrid to excel in asp.net1.1
my code is:---
Private Sub btnExport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExport.Click
Response.ContentType = "application/vnd.ms-excel"
' Remove the charset from the Content-Type header.
Response.Charset = ""
' Turn off the view state.
Me.EnableViewState = False
'Dim tw As New System.IO.StringWriter
tw = New System.IO.StringWriter
'Dim hw As New System.Web.UI.HtmlTextWriter(tw)
hw = New System.Web.UI.HtmlTextWriter(tw)
' Get the HTML for the control.
DataGrid1.RenderControl(hw)
' Write the HTML back to the browser.
Response.Write(tw.ToString())
' End the response.
Response.End()
End Sub
whenever i run this code i got the error message that control datagrid1_....
must be placed inside a form tag with runat=server.
how to resolve it as all the controls are inside the form tag and runat=server attribute is also there.
Plz suggest.
|
|
|
|