|
|
hey guys
i have a drop down list in my DetailsView control that when the DetailsView DataBinding event calls i'd like to ptogramitically select a certain item in it
i used this code but it returns an error:
(Object reference not set to an instance of an object.)
protected void DetailsViewEditLink_DataBinding1(object sender, EventArgs e)
{
DropDownList drpEditType = new DropDownList();
drpEditType = (DropDownList)DetailsViewEditLink.FindControl("drpEditType");
drpEditType.SelectedValue = [SomeValue]; //Error happens in here
}
I'd like to know why this error happens
troubling shoot tips were:
1. use the "new" keyword to create an object instance (which i did or didnt i?!)
2. check to determine the object is null before calling the method (what object is null?!)
thank you so much
|
|
|
|
|
Farhad Eft wrote: drpEditType = (DropDownList)DetailsViewEditLink.FindControl("drpEditType");
If FindControl() is not getting the control, it will return a null value.Always check for null before you do something with that object. This is the way to avoid error.
Farhad Eft wrote: use the "new" keyword to create an object instance (which i did or didnt i?!)
Here no need to use the new keyword. You are assigning the reference here.
|
|
|
|
|
oh i see
so can you please tell me how can i find a specific control like a drop down box that i put in one of edit item templates of my DetailsView template fields.
|
|
|
|
|
On the prerender method of the detailsview
Ask for the currentmode
<br />
If Me.dv.CurrentMode = FormViewMode.Edit Then<br />
CType(Me.dv.FindControl("controlid"), DropDownList).Selectedvalue = YourValue<br />
End If<br />
Alexei Rodriguez
|
|
|
|
|
How do you guys handle exceptions in ASP.NET applications? Client-side pop-up tricks? Catch and redirect to a helpful error message page, or default and redirect to a general error page? Change views from a capture view to an error view? The way I think I should be going about this is:
Client-side validation messages etc.
Server side catch specific exceptions only at top level, i.e. in Page code, and redirect to or present task specific error message.
Server side "auto" redirect for all other exceptions.
Pits fall into Chuck Norris.
|
|
|
|
|
Brady Kelly wrote: How do you guys handle exceptions in ASP.NET applications?
That's a requirements related question so the answer can be different from company to company as well as application specific. There is no cook book answer to that question.
That said, most server based processes should log things as this makes problem solving much simpler. That's not saying that desktop applications should not log.
ASP.NET has some default message options that you should understand before deciding. In our case we just use those and in conjunction with logging we have found it works just fine for us.
led mike
|
|
|
|
|
Hi
I am having problems getting set focus to work, I have a page with numerous user controls on it but always need the focus to return to one text box following postback. - This control is also within its own user control.
I have stripped out lots of code to try and track down the error, my current position is as follows.
The main page has one button on it, to force a postback, there is no code within the onclick event. The page has one user control, SwipeCard2
This user control has an update panel on with updatemode set to conditional, a text box (txtswipe) and a label lblError.
This control has the following code which is used to register the javascript to set the focus
Public Sub SetFocusToControl(ByVal page As System.Web.UI.Page, ByVal control As System.Web.UI.Control)
Dim strScript As String = String.Format("document.getElementById('{0}').focus();", control.ClientID)
strScript = String.Format("<script language=""JavaScript"">{0}</script>", strScript)
page.ClientScript.RegisterStartupScript(Me.GetType(), "setFocus", strScript)
End Sub
Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
' CSBSetFocus()
SetFocusToControl(Page, Me.TxtSwipe)
Me.UpdatePanel1.Update()
End Sub
The above code works a treat, if you click anywhere on the page to remove the focus, then click on the button, the cursor is returned to the text box within the user control.
I have now added the following code to the TextChanged event
Me.lblError.Text = "This is not a supervisor account!"
Me.TxtSwipe.Text = String.Empty
Me.UpdatePanel1.Update()
Now the cursor will not appear in the textbox following postback,
Any ideas?
Regards
Tom
|
|
|
|
|
If anybody else wants to know the fix put
ScriptManager.GetCurrent(Page).SetFocus(Me.txtScan)
in pre render of the control
|
|
|
|
|
hi all
i have a problem please suggest me the solution
i have a datagrid which consists of bounded columns
i need to get the column number or column index
datagrid sample is like this
where heading channel and corporate are link buttons dynamically displayed
slno | region Name |channel | corporate|
1 | abc |ruleset | forapproval
2 | a23 |ruleset | forapproval
3 | 2asdas |ruleset | forapproval
4 | adas |ruleset | forapproval
so when i click on channel->ruleset i need to get the column no as 2..
based updon the column number i need to display the details
if 2 then channel details else corporate details
please .. its very urgent
|
|
|
|
|
Hi,
I would make the column ruleset a LinkButton.
In your aspx you create a TemplateField that has a LinkButton like:
<asp:LinkButton runat="server" ID="lbRuleSet" CommandName="EditGrid" OnCommand="Grid_OnCommand" />
In the codebehind you create a Method like:
protected void Grid_OnCommand(Object sender, CommandEventArgs e)
{
LinkButton btn = (LinkButton)sender;
GridViewRow row = (GridViewRow)btn.NamingContainer;
if (e.CommandName.Equals("EditGrid"))
{
MyGridView.SelectedIndex = row.RowIndex;
MyGridView.SelectedIndex = -1;
}
}
|
|
|
|
|
Hi guys...
OK, picture the scene if you will...a standard SP returns some codes and VAT values. The codes are in varchar(3) fields.
This data is then bound to a DataList - not directly, but with an Item template, containing a drop down list for the rates. Now when binding, the values are correctly added to the ddl, but the selected value is not being set correctly. Looking at the code, when I do the databind, the column is indeed "1" or "x" or whatever...so far so good, but in the databind event handler, when I look at e.Item.DataItem's version of the value (used to determine which item to select), it's being returned as "1 " or "x "
Anyone seen anything similar? It's almost as though the function call to the bind event is what's doing the mangling. but I can't see how!
I've also tried changing the column to a varchar (1) in the database, but bizarrely, it still appears as "1 " in the bind event. To add even more complexity(!) this is only ocurring on a client's dataset - on our "reference" dataset, with similar data, all is fine...
C# has already designed away most of the tedium of C++.
|
|
|
|
|
I vaguely recall wrestling with something like that that, and I don't believe I resolved it. I think I just worked around it.
Pits fall into Chuck Norris.
|
|
|
|
|
Hi there,
How can i check the font used in different cultures?
Suppose i'm changing the culture as "hi-IN", where i can see the font using for hi-IN?
Regards n Thks
Sam.M
|
|
|
|
|
Hi sam,
generally you can test it through various free translator, available on net...
for example use this : http://www.freetranslation.com
|
|
|
|
|
helooooooooooo Every Body
how to use smtp.gmail.com for sending mail. its free Server please help me
Thanku
Piyush Vardhan Singh
p_vardhan14@rediffmail.com
http://holyschoolofvaranasi.blogspot.com
http://holytravelsofvaranasi.blogspot.com
|
|
|
|
|
Have you tried smtp.google.com?
Regards n Thks
Sam.M
|
|
|
|
|
yaaa i use this in last night but it give athentication errro
Piyush Vardhan Singh
p_vardhan14@rediffmail.com
http://holyschoolofvaranasi.blogspot.com
http://holytravelsofvaranasi.blogspot.com
|
|
|
|
|
|
i have alredy use this and i usee id and password of my gmail Account. it right way to go??
i will catch u ofter 1 hr. if u have any yahoo id then frwd me...
byeee
Piyush Vardhan Singh
p_vardhan14@rediffmail.com
http://holyschoolofvaranasi.blogspot.com
http://holytravelsofvaranasi.blogspot.com
|
|
|
|
|
i work on .net2008 on vista operating system and vista have not SMTP server so i want use this...
Piyush Vardhan Singh
p_vardhan14@rediffmail.com
http://holyschoolofvaranasi.blogspot.com
http://holytravelsofvaranasi.blogspot.com
|
|
|
|
|
Set TLS Authentication is True and Specify the correct Port No.
Parwej Ahamad
|
|
|
|
|
When I download a file it gives other filename if containing more than one dot(.), for example
download file : application.it.pdf
Then it will display : application[1].it.pdf...
how to contain the same file name during downloading....
I'm using following code :
------
-----
FileInfo f = new FileInfo(docname);
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(f.Name));
Response.AddHeader("Content-Length", fileSize.ToString());
-----
-----
any suggestions .....
Thnx in advance...
|
|
|
|
|
Hi friends.
I want to capture right click event on any image.
I need to implement menu controls on right click event of image.
Can any body guide me how to implement this or give me some reference sites?
thanks in advance
please don't forget to vote on the post that helped you.
|
|
|
|
|
I know you can capture right clicks and suppress them, so I see no reason why you couldn't use the same code to bring up a javascript menu.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|