|
munklefish wrote: Object reference not set to an instance of an object.
Do you mean you get this error at the server side?
Because, the textbox is placed inside a FormView which is a naming container, so make sure that you call FormView1.FindControl("TextBox1") (assuming the FormView1 is the id of the FormView control). If you simply call the FindControl("TextBox1"), it's assumed that you call the method of the Page instance, and it only searchs for the textbox in the scope of the Page, not the FormView. For more information, see Accessing ASP.NET Controls Programmatically [^]
|
|
|
|
|
Hi,
I tried doing this in FormView and Repeater etc etc. However it still comes up with the same error. I have also tried to FindControl using the appropriate display method as the prefix eg Repeater1.FindControl("TextBox1") but it still says the object reference is invalid.
Could this be anything to do with the fact that im using the SQLDataSource wizard and binding it on 'Page_Load' ? Ie so effectively when i click the reset or submit button in my form, the page is reloaded and thus the referenced TextBox isnt actually available for this minute period of time during which the SQLDataSource reloads the Repeater / FormView data?
Is there anyway to add the equivalent of if(!Page.IsPostBack) to stop the Data rebinding on Postback / when a button is clicked?
Thanks.
|
|
|
|
|
I finally found the perfect solution to this problem.
You can simply capture the SqlDataSource created by the wizard, and then convert it into a new DataReader instance in the code behind file.
SqlDataReader reader = (SqlDataReader)<br />
SqlDataSource1.Select(DataSourceSelectArguments.Empty);
You can then manipulate the data in just the same way as you would a conventional / hand coded DataReader.
Hope this might help others in future. Thanks for everyone who gave advice.
|
|
|
|
|
Hi,
I have a column in my DataGrid which represents a foreign key. At the moment, it displays the ID for that key. I want it to display another column instead..
For example:
User Table has (ID, Title, Firstname, Lastname)
Title Table has (ID, Mr, Mrs)
I want the data grid to show "title" as "Mr" or "Mrs" instead of "01" or "02",
Please help, Thanks!
|
|
|
|
|
Try this......
go to Datagrid property builder.. select the Bound column for ID and set its Text Field as Mr or Ms but DataField as ID
should work
Sanjeev
|
|
|
|
|
Sorry I should have been clearer...
The Title Table is expandable. So "Ms" and "Miss" and say "Master" can be added at a later date. This means the Column will be able to display the "title" dynamicly by querying the Title Table.
Otherwise, the senario would be that I would just be able to input "Mr" and "Mrs" as regular strings.
My issue is how exactly to query the table. I know I have to use an SQL View, but my efforts have been in vain
|
|
|
|
|
put your code in The ItemDataBound Event of the Datagrid.
Thanks & regards,
Suresh Dayma
Everything Is Possible!
|
|
|
|
|
Here is the code from ASP.NET 1.1 that works. My problem is below with 2.0 GridView?
private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
int playerID = Convert.ToInt32(e.Item.Cells[1].Text);
string sqlDelete = "delete Players where PlayerID = '" + playerID +"'";
SqlConnection conn = new SqlConnection(dsn);
SqlCommand cmd = conn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = sqlDelete;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
DataGrid1.EditItemIndex = -1;
BindGrid();
}
This above code is ASP.NET 1.1 code for Deletion from DataGrid. It works fine. Now, I am using GridView (ASP.NET 2.0) The problem I am having is getting the playerID from GridView?
***int playerID = Convert.ToInt32(e.Item.Cells[1].Text); **
does not give any playerID but throws error? How do I get the playerID from GridView. Is the event handler Row Deleting or Row Deleted?
Please help.............
-- modified at 16:34 Wednesday 27th September, 2006
Sanju
|
|
|
|
|
could you please post the error message you're getting?
|
|
|
|
|
Thanks for you immediate reply........
Here is the error !!!
'System.Web.UI.WebControls.GridViewDeleteEventArgs' does not contain a definition for 'Item'
How do I retrieve PlayerID from the GridView?
Thanks
Sanjeev
|
|
|
|
|
San, that is weird, it is the sam way I do it (in VB.net) under the DataGrid Delete or Edit item methods (ASP.NET 1.1) , honestly I never worked with an ASP.NET 2.0 GridView object before.
Sorry!
|
|
|
|
|
I want to pass TWO parameter to crystal report but it is always second one applied , I'd be pleased if anybody help me.Thanks
Mazy
"One who dives deep gets the pearls,the burning desire for realization brings the goal nearer." - Babuji
|
|
|
|
|
Hi,
A simple question....
In my aspx page, i am having some LinkButtons, with CommandName property. When i click a control, the page will post back.
I wish to know, which control is the source of this Postback, during Page_Load event iteself? NOT in that LinkButton's Command event.
How to perform this?
Regards,
Jay
|
|
|
|
|
|
Hi,
It works fine. I ve just used C#. But i have another query.
It says that,
Dim ctlName As String = targPage.Request.Form("__EVENTTARGET")
does not work if the postback is caused by standard buttons.
can u explain me the reason.
Thanks.
Regards,
Jay
|
|
|
|
|
hi
i need to get a value of html hidden control which is not set to runat server and i also dont have its id only name is getting.
Request.form["refid"] is not working. so
can u sugges some idea
regards
max
|
|
|
|
|
add runat="server" (from the html view) as a property of your hidden field, it will continue to work as a hidden field and it will allow you to read its value in the code behind. It might have a different way to solve this issue but this worked for me. Let me know if it works for you.
|
|
|
|
|
Dont mistake me, i have an small doubt, did you declared the tag inbetween the tags???? Because all other things are correct.
Know is Drop, Unknown is Ocean
|
|
|
|
|
Exelioindia,
Yes; like I said on my reply, it might be a different approach to solve this issue but this worked for me.
|
|
|
|
|
If you have put the hidden field inside the form that you are posting, you can get the value using Request.Form.
---
b { font-weight: normal; }
|
|
|
|
|
it will be generated as a System.Web.UI.HtmlControls.HtmlInputHidden and you can acess (get/set) its value using: fieldName.value.
David
|
|
|
|
|
dgonzale wrote: it will be generated as a System.Web.UI.HtmlControls.HtmlInputHidden and you can acess (get/set) its value using: fieldName.value.
Only if you add the runat and id properties to the element. Otherwise the element is treated as plain text by the server.
There is no need to make a server element of it to access the value that it sends in the post.
---
b { font-weight: normal; }
|
|
|
|
|
Ooops! Yes you're right, i forgot about the id property, thanks Guffa.
David
|
|
|
|
|
Hi to all,
I need to POST To A Different Site in asp.net (vb.net) after users enter required data filds in a form. Specifying action (containing the URL of the site) and the target (_blank) does not help, it opens my site again.
I’ll appreciate any help,
Regards,
David
|
|
|
|
|
in the form's action specfiied fully qualified URL of the page which it has to call such as
<form method="post" action="http://callingsite.com/authen.aspx">
and verify the field/value names that you are passing to the page are similar or not.
If this one not a solution, be specific of what are you doing and how you are doing it?
|
|
|
|