|
I have a gridview that has some prices that is dispayed as strings.
In the database these prices are nvarchar datatype.
I need to sort them in the gridview as numbers because they are not sorted correctly as strings but at the moment I can't change this datatype in the database. So is there any workaround to sort this column as numbers? how?
|
|
|
|
|
Wouldn't you just convert the string to an int, if so Convert.ToInt32...something like that maybe
|
|
|
|
|
how can I do that?
do I have to do it inside the sorting event??
How..details plz.
thanks
|
|
|
|
|
Try sherin's suggestion below first to see if that helps you, if not convert string to int
|
|
|
|
|
Put it around your value e.g. Convert.ToInt32(value in here)
|
|
|
|
|
Convert your price field to integer in the query...
SELECT Your_Fields FROM Your_Table WHERE Your_Condition ORDER BY CAST(Your_Field AS INT)
EVEN THE WORD IMPOSSIBLE SAYS I M POSSIBLE.
|
|
|
|
|
The problem is that I'm using the SortExpression property of the gridview's databound item. The sortExpression property only takes that column name to be sorted so how can I add this Cast(field As Int)??
|
|
|
|
|
Try casting in your select
select column1, column2,CAST(columnn3 AS INT) as column3 from table
This will return an int column to your grid, problem solved.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
EVEN THE WORD IMPOSSIBLE SAYS I M POSSIBLE.
|
|
|
|
|
Got It
CAST In Your Select Sql Query
Select field1,CAST(Price AS INT) As Price,.......
EVEN THE WORD IMPOSSIBLE SAYS I M POSSIBLE.
|
|
|
|
|
Thanks a lot, I think this is gonna work.
|
|
|
|
|
Thats what I said - do the cast in the query, it then returns the correct datatype.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Your design is broken. Why you need to keep prices in NVarchar field ? How are you binding this grid view ? Using a DataTable ? If yes, after filling the data table, change the column type to integer or double. So gridview can sort it correctly.
|
|
|
|
|
I need to know how can I bind my gridview from a pop up window?
I have a gridview on a parent page and then a user can open a pop up window to perform some changes on the gridview in the parent page after that he closes the window. Right then I need to bind the gridview on the parent page to view the changes that the user did from the pop up window.
How can I do that?
|
|
|
|
|
OK so you want the following to happen:
User views gridview in mainpage
user edit gridview in new window
user views gridview in mainpage with updated values.
The thing is when the new window closes its not very easy to navigate a user back to the mainpage and then refresh that page to reflect the new changes.
Instead of opening a new window(which may be blocked by pop-up blocker) keep them in the same window and user query string to transfer the values.
|
|
|
|
|
thanks for the repy, but there is no way I can do all the editing on the same page. The only way is to use a pop up window.
Is there any other solution for this?
|
|
|
|
|
No, because as soon as you open a pop-up window your application is split in two and they can now continue navigating around the mainpage even with the pop-up open.
best to keep it all in the same window anyway
|
|
|
|
|
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string s17 = Request.Form["scheck"].ToString();
scheck.Value = s17;
Response.Write(s17);
string s18 = Request.Form["sacc1"].ToString();
sacc1.Value = s18;
Response.Write(s18);
string s19 = Request.Form["schild"].ToString();
schild.Value = s19;
Response.Write(s19);
string s = Session["child"].ToString();
//Response.Write(s);
//Response.Write(s19);int.Parse(Request.Form["schild"])==1
if (int.Parse(s19)== 1)
{
Session["a"] = ctcchild1.name;
Session["b"] = ctcchild1.age;
Session["c"] = ctcchild1.college;
}
else if (int.Parse(s19)==2)
{
Session["d"] = ctcchild2.name;
Session["e"] = ctcchild2.age;
Session["f"] = ctcchild2.college;
}
//else
//{
else if (2<int.parse(s19)><= 3)
{
Session["g"] = ctcchild3.name;
Session["h"] = ctcchild3.age;
Session["i"] = ctcchild3.college;
}
else if(int.Parse(s19) == 4)
{
Session["j"] = ctcchild4.name;
Session["k"] = ctcchild4.age;
Session["l"] = ctcchild4.college;
}
how to apply condition at this place
plz tell me
thanks
|
|
|
|
|
what do you mean by
gaurav mangal wrote: how to apply condition at this place
|
|
|
|
|
gaurav mangal wrote: if (int.Parse(s19)== 1)
{
Session["a"] = ctcchild1.name;
Session["b"] = ctcchild1.age;
Session["c"] = ctcchild1.college;
}
else if (int.Parse(s19)==2)
{
Session["d"] = ctcchild2.name;
Session["e"] = ctcchild2.age;
Session["f"] = ctcchild2.college;
}
//else
//{
else if (2<int.parse(s19)><= 3)
{
Session["g"] = ctcchild3.name;
Session["h"] = ctcchild3.age;
Session["i"] = ctcchild3.college;
}
else if(int.Parse(s19) == 4)
{
Session["j"] = ctcchild4.name;
Session["k"] = ctcchild4.age;
Session["l"] = ctcchild4.college;
}
if you have conditions like this, how would u retrieve correct data back from Session ???
apr ~ asp
|
|
|
|
|
then plz tell me what should i do.
|
|
|
|
|
actually i am taking value from one page to other page using sessions .
but i want at secont page that if the value of session["s1"] ==2 to webcontrol should be generate two times.and it ==3 then usercontrols should be generate 3 times .so i have to apply condition :
if(session["s1"]==1)
{
}
if(1<session["s1"]><=2)(error)
{
}
now i get error:
Operator '|' cannot be applied to operands of type 'bool' and 'int'
what should i do.
thanks
|
|
|
|
|
gaurav mangal wrote: if(1<session["s1"]><=2)
That if condition is totally wrong!
I'm not able to understand what you are trying to do here.
Can you please explain?
EVEN THE WORD IMPOSSIBLE SAYS I M POSSIBLE.
|
|
|
|
|
thanks for the response.
actually i want that if a user select 2 from dropdownlist or 3 or 4 .
then at second page 2 or 3 or 4 usercontrol will create .so i have
tha value of dropdownlist in sessions .
and want to apply condition on that .
this is the code .
or you suggest what should do.
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string s17 = Request.Form["scheck"].ToString();
scheck.Value = s17;
Response.Write(s17);
string s18 = Request.Form["sacc1"].ToString();
sacc1.Value = s18;
Response.Write(s18);
string s = Session["child"].ToString();
//Response.Write(s);
//Response.Write(s19);int.Parse(Request.Form["schild"])==1
if (int.Parse(s)== 1)
{
Session["a"] = ctcchild1.name;
Session["b"] = ctcchild1.age;
Session["c"] = ctcchild1.college;
}
else if (1<int.parse(s)><=2)(error)
{
Session["d"] = ctcchild2.name;
Session["e"] = ctcchild2.age;
Session["f"] = ctcchild2.college;
}
//else
//{
else if (2<int.parse(s)><=3)(error)
{
Session["g"] = ctcchild3.name;
Session["h"] = ctcchild3.age;
Session["i"] = ctcchild3.college;
}
else if(int.Parse(s19) == 4)
{
Session["j"] = ctcchild4.name;
Session["k"] = ctcchild4.age;
Session["l"] = ctcchild4.college;
}
|
|
|
|
|
I'm not able to understand why you are doing in this way.
How do you know that total number of user controls you are creating.
Because, if you are using if there always will be a limit.
Why cant you do something like below
<br />
int totalControl=0;<br />
if(Session["child"]!=null)<br />
{<br />
totalControl=int.Parse(Session["child"].ToString());
for(int curControl=0;curControl<totalcontrol;curcontrol++)><br />
{<br />
}<br />
}<br />
EVEN THE WORD IMPOSSIBLE SAYS I M POSSIBLE.
|
|
|
|