maybe there is a simpler solution, but you could use the rowdatabound event
of your gridview and set the index of the dropdown there appropriatly (if in edit mode).
Here is an example (which is using c1gridview, just replace it by the microsoft one and
check the if conditions, they may be slightly different)
protected void grdRoomTypes_RowDataBound(object sender, C1.Web.UI.Controls.C1GridView.C1GridViewRowEventArgs e)
if (e.Row.RowType == C1.Web.UI.Controls.C1GridView.C1GridViewRowType.DataRow)
if ((e.Row.RowState & C1.Web.UI.Controls.C1GridView.C1GridViewRowState.Edit) > 0)
// here find your dropdownlist by id and set the index
TimeSchemeEditor editor = (TimeSchemeEditor)e.Row.FindControl("timeSchemeEditor");
editor.TimeScheme = (ServiceDirectoryRoomTypeItem)e.Row.DataItem;
// Do nothing here maybe
TimeSchemeViewer viewer = (TimeSchemeViewer)e.Row.FindControl("timeSchemeViewer");
viewer.TimeScheme = (ServiceDirectoryRoomTypeItem)e.Row.DataItem;
I guess in your markup, you have an edititemtemplate and an itemtemplate, is that right?
In your rowdatabound event, it depends on the current rowstate, which controls exist and which not. For example, if you have a label in your itemtemplate and a dropdown in your
edititemtemplate, then the label will be null if rowstate == edit and the other way around.
So first check if RowState == Edit and then find your dropdown. you will not find the
controls shown during "view" rowstate (dont read viewstate:P).
Ok. Thanks a lot Michael. I have EditItemTemplate and ItemTemplate. As you said, I checked now only the dropdownlist and I'm getting the object. But how will I fix the selected value. Still it is displaying only the first value.
you have to set the SelectedIndex of your DropDownList in this event (according
to the value of your DataItem)
Try something like this:
protected void grdTCCRics_RowDataBound(object sender, GridViewRowEventArgs e)
if (e.Row.RowType == DataControlRowType.DataRow)
if ((e.Row.RowState & DataControlRowState.Edit) > 0)
DropDownList ddlRegion = (DropDownList)e.Row.FindControl("RegionCodeList");
if (ddlRegion != null)
// You have to replace VALUEFROMDATAITEM by the current region
// value of your DataItem (look in e.Row.DataItem, i dont know it)
ListItem item = ddlRegion.Items.FindByValue("VALUEFROMDATAITEM");
ddlRegion.SelectedIndex = ddlRegion.Items.IndexOf(item);
//string strregion = ddlRegion.SelectedItem.Text;
// You dont retrieve the value of the dropdown here, you set it
I have needed to insert and update DateTime Field in MSSQL Database Table. I am using Text Querry. My input Control is TextBox where the format of Date is "dd/MM/yyyy". In Database it should be save as "yyyy-MM-dd". I have used a Function to convert Date Format as:
public static string ConvertToDate(string pstr)
result = "'" + Convert.ToDateTime(str).ToString("yyyy/MM/dd") + "'";
result = System.Data.SqlTypes.SqlDateTime.Null.ToString();
The string Data Returned after conversion is used for insertion.
I I execute Application Visual studio by compiling it works well. but when i make virtual Directory of this application and run this through browser it doesn't work.
I love to learn about HTTP as much as possible. From a long time, I am hearing that, I should use SSL when passing sensitive data. Because, a man in the middle can capture the plain text sensitive data while I am sending the data from my browser to a website. Ok, but I did not find any article talking about how those 'man in the middle' people capture the data !! I searched in google, did not find any! Looks like I am protecting my data using SSL against a mechanism of attack and the mechanism is not available to public. I am highly curious to know about it. Can anyone please give me some links / articles about this ?
By the way, it is just for learning intention. Should it be rude or indecent to discuss about this topic or if it is a sensitive matter, then, you wont have to tell me. But please at least tell me that if it is legal or illegal to learn about it !!
But I highly doubt anyone here is going to help you code a virus, not saying that is your intention although it sounds extremely suspect , but by intercepting data sent from the client to the server would definitely be a piece of malicious code that I’m sure the end user would not be aware of.
The reason you can't find any information on how to actually implement this is ... well ... just what I said above, it's just not ethical and therefore you will not find it on 'reputable' site such as The Code Project and the less than reputable ones that will actually give you that information will likely infect your browser and your computer with herpes or something you would probably be safer bare backing a $10 ‘Lady of the Evening’
If at first you don't succeed ... post it on The Code Project and Pray.
Thanks a lot for your reply. I understood the point. So, someone learned this technology and causing a threat for us who worry about protecting our website from them using SSL. But, how that 'someone' learned this technique as there is no article about it anywhere !! For example, if I want to make a software or technology to protect against 'Man in the middle', I will need to learn about it first!, right ? So, even for a honest intension, this technology is not available for public! Is it something like, I will need to experiment about HTTP a lot in my lab and after spending years, I will understand what and how !! If I want to make a software to protect from this attack, I need to go thru all of this 'RE INVENTING THE WHEEL' ? Just because, no one will tell me how this attacks are happening !!
Anyway, thanks agian. The topic is very interesting for me to discuss. I would love to hear more replies about it.
I think you might be missunderstanding the actual issue.
The issue is that someone has infected either the client machine, a 'man in the middle' server or the actual server itself.
There really isnt much you can do to prevent that as these are things that happen far beyond the control of your server side code.
The reason that people are telling you to implement SSL to avoid the *potential* for this type of attack is because SSL simply encrypts the data before it is sent from the client machine to the server and then it is decrypted on the server side for your code to use.
So long story short, there is nothing you can do aside from enabling SSL on your server which is something you should do anyways if you are dealing with sensitive information.
If you really just want to learn more about that type of attack i would suggest Wikipedia or something of the sort, but im pretty sure your not going to get a bunch of web developers to tell you how to intercept their data
If at first you don't succeed ... post it on The Code Project and Pray.
I am implementing Routing in my ASp.NET Web Form Application (.NET 4.0). I guess, Routing always consider the same protocol where the request is coming form. I mean, if my browsing page has url as 'https://www.myDomain.com/login.aspx' and if I have a link in this page which points to a Route, then, my application will redirect to the routing page (by clicking the link) which will be of 'https' protocol. (right ?), in that case, how can I enforce my application to use 'http' protocol in the redirected page using Routing ?
I want to generate the routing url from my code. I learned GetRouteUrl(string routename, routeparameters) will generate the url for me, but how can I get absolute url with http or https for a route ?
I have a listview inside a DIV which shows the scroll bars. At one time, let's say, 10 rows can be seen. I scroll down and click Edit on 25 row. To my surprise, the scroll goes to the first row (although if I go back to 25th row, the row is in edit mode)
My issue, how I can make sure that the scroll bar maintains its position to 25th row after clicking on Edit button?
Looks like you page gets a postback when you click the edit link.
If so, try to set the Page.MaintainScrollPositionOnPostBack Property to true to return the user to the same position in the client browser after postback. (i.e. enabling smart navigation, see if it works!)
I am make simple application that send mail automatically after ending week .... so i don't know where i write my code ... what i do i am write my code in button and when i click on button , message sent to all members but i want this done automatically without admin clicks ... just sets date and message sent .
Last Visit: 4-Apr-20 5:17 Last Update: 4-Apr-20 5:17