|
Ok, it seems as though this was happening because the page got redirected before it even loaded the first one and for some reason the first session starting wasn't good enough.
|
|
|
|
|
I want set properties to a WebControl via Reflection. The corresponding code snippet is something like this:
public void SetProperty(Control control, string propertyname, string propertyvalue)
{
Type type = control.GetType();
System.Reflection.PropertyInfo pi = type.GetProperties(propertyname);
object value = Convert.ChangeType(propertyvalue, pi.PropertyType);
pi.SetValue(control, value, null);
}
It works for most cases, but for special types like Unit or Color (Width or ForeColor for example), I get an Exception. I made some ifs for a few types so that I convert/parse them specifically to the type needed. But this way the code is quite ugly and is not guaranteed to work all the time. Anyone else know a better solution?
|
|
|
|
|
szukuro wrote: Anyone else know a better solution?
As long as I I don't know what your context is, for example why you need reflection here, then IMO it's hard to say this is a good/bad choice or whether there is a better one.
|
|
|
|
|
It's for a hobby project, kind of a WYSIWYG editor, but with server-side features. At this state the user types in some markup like <asp:TextBox ID="TextBox1" runat="server" /> and gets a TextBox created on the same page (via Ajax).
|
|
|
|
|
|
Thanks for the link, I didn't know of this method. This way I think the whole thing will be much easier to write .
Also despite this, I think my question still remains in a more general sense: How do/Can you set properties independent of their types easily (= without if and/or switch) from string input? Though now it's not really an ASP.NET question anymore..
|
|
|
|
|
In this case, you should use the the type converter of the property to convert a string value, this way will work not just with the primitive types, but also with custom types. To get the TypeConverter[^], you can use the TypeDescriptor[^], your sample code is updated a bit like this:
public void SetProperty(Control control, string propertyname, string propertyvalue)
{
Type type = control.GetType();
System.Reflection.PropertyInfo pi = type.GetProperty(propertyname);
TypeConverter converter = TypeDescriptor.GetConverter(pi.PropertyType);
object value = converter.ConvertFromInvariantString(propertyvalue);
pi.SetValue(control, value, null);
}
|
|
|
|
|
|
How do I display negative amounts in GridView control?
thanks,
Murthy here
|
|
|
|
|
Murthy Puvvada wrote: How do I display negative amounts in GridView control?
The same way you display positive amounts.
|
|
|
|
|
Maybe he has GridView with -5 rows...
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus
|
|
|
|
|
Best Regards,
Apurva Kaushal
|
|
|
|
|
Try to be more concrete.. Negative amounts of what? Negative numbers? And, what did you try? What it did you didnt like?
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus
|
|
|
|
|
Sorry that i am not clear.
but I have this $ Amount field and the negative dollar amounts come up as follows:
-36000$ displayed as ($360000)
I hope it makes my issue clear.
Thanks,
Murthy here
|
|
|
|
|
Murthy Puvvada wrote: but I have this $ Amount field and the negative dollar amounts come up as follows:
-36000$ displayed as ($360000)
Yes, that is how the culture that you are using is defined to display a negative amount.
I hope it makes my issue clear.
As you haven't said anything about what you think is wrong about this, the issue is not clear at all.
---
single minded; short sighted; long gone;
|
|
|
|
|
sorry again,
how can i change the culture to display $amounts as -$36,000 instead of ($36000)?
thanks again,
Murthy here
|
|
|
|
|
I’m populating a GridView control on an ASP.NET web page using a SQL Server 2005 stored procedure. The following subroutine is how I populate the GridView Control:
Protected Sub Load_grdEmployees()
'Purpose: Loads the grid control grdEmployees
' with employee information
'Parameters: None
'Returns: Nothing
Dim dr As SqlDataReader
Dim cn As SqlConnection = New SqlConnection(MRMFunctions.WebConfigConnString)
cn.Open()
Try
Dim cd As SqlCommand = New SqlCommand("mrmsp_EmployeeList", cn)
cd.CommandType = Data.CommandType.StoredProcedure
dr = cd.ExecuteReader
grdEmployees.DataSource = dr
grdEmployees.DataBind()
Catch ex As Exception
Msg = ex.Message
lblErr.Visible = True
lblErr.ForeColor = Drawing.Color.Red
lblErr.Font.Bold = True
lblErr.Text = Msg
Finally
cn.Close()
End Try
End Sub
The problem I’m having is I don’t know how to read the data stored in the first column on the GridView Control. I use the ID number stored in the first column to perform edits on selected records. I’m not using a SqlDataSource control on this web page.
Does anyone have any ideas on how to do this?
Thank you,
Quecumber256
|
|
|
|
|
Quecumber256 wrote: The problem I’m having is I don’t know how to read the data stored in the first column on the GridView Control.
+ You can get reference to the first cell of a row to get the value.
+ Another option is to store the key values using the DataKeyNames[^] property and you can access the value from the DataKeys collection.
|
|
|
|
|
I didn't place a SqlDataSource Control on the web page. I think because I don't have this control on the page there are no references to the DataKeyNames and DataKeys properties.
I spent the whole day trying to find examples on how to set these properties through code. However, everything I did find required that a SqlDataSource Control be present.
My web page requires a greater amount of control than the SqlDataSource will allow.
Thank you for your help,
Quecumber256
|
|
|
|
|
Actually, you can set the DataKeyNames property either in the control definition or in code, the values should be taken from the result data reader. For example:
GridView1.DataKeyNames = new string[] { "Id" };
....
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
object key = GridView1.DataKeys[e.NewEditIndex].Value;
}
|
|
|
|
|
I'm using Visual Studio.Net 2003, Asp.Net1.1.
I have a datalist bound from a database and loaded with some Names.
I want to fire an "onClick" event when I select an element from the datalist.
How can I do that from the HTML code.
Please it's very urgent.
|
|
|
|
|
Since you have been around here for 2 years, 10 months according to your profile, I'm sure you realize posts flagged as URGENT are usually ignored.
only two letters away from being an asset
|
|
|
|
|
Never knew about that..lol
|
|
|
|
|
Hi EveryBody
Im using ASP.NET with VS 2005 and trying to make report with Microsoft Reporting Service. Those error Im getting is follows.
1.Report Viewer cant change the report. Example I got a TextBox under a Button where I can put a CustomerID in TextBox. I have put a CustomerID 1001 inside the TextBox and Clicked the Button, 1st Time Im getting the whole informations about that particular Customer. When I have changed the CustomerID like 1002 then !!! inside the code is working properly and the DataSet shows the information about that CustomerID 1002 but ReportViewer cant change the Customer Informations its remain same. Still its showing 1001 informations.
2.A data source instance has not been supplied for the data source 'DataSetAUDITLOG_CountLessons'. I have created 2 tables inside the DataSetAUDITLOG after that I have deleted CountLessons table from DataSET and Im not using this Table anymore and there is no relation with table anywhere. So why Im getting this error.
3. On the otherhand I want to send a CustomerID value to another page from a ReportViewer. Could you please tell me. How can I do it? If you have any project example about this please send me.
I need your help
Thanks
Sarfarj Ahmed
Sarfarj Ahmed
|
|
|
|
|
How can i change the page index of a datagrid from code??? I want that everytime the grid loads the default should be page1.In my code this doesn`t happen. I have created a div which acts like calendar control ie it displays currently selected month,prevmonth & nextmonth link. I show employee info i a datagrid for the selected month. The problem is with paging . Here`s the problem.
Suppose for current month i have information which is 2 grid pages long and for next month it has only 1 page. when i select page 2 in current month and clickthe nextmonth it retains its pageindex2 and thus gives an error "Page index must be >=0 and <pagecount.
Help!!!
-- modified at 8:49 Wednesday 7th February, 2007
|
|
|
|