datagrid,spliting value from database

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

VAR1 = 3/4
VAR2 = 2
I user can submit the values "3/4" or "2" (VAR1, VAR2 represent any numbers)
when user submits "3/4" we assume 1sthalf/2ndhalf
These values are saved into database as a row
row1: 3/4
row2: 2

I have a datagrid that displays values just fine, but user wants to beable
to click on the 3 or 4 when we have a "/" in the value.
How do I split the value when it finds a "/" ,
then create a button column(for an event) for each value. This would allow
the user to click the 3 "or" 4 in 3/4 and then i could run an event based on
what they clicked.
so,
I was thinking
<a href="p.aspx?id=1sthalf&value=3">3</a> /
<a href="p.aspx?id=2ndhalff&value=4">4</a>
I don't know how to do something like this in the data grid and/or datalist.
If it doesn't find a "/" it should assume 1sthalf.
Any ideas, hints, HELP would be GREAT!
 
Yes, but how do I make that work inside the datagrid ?

Brock Allen said:
string s = "3/4";
string[] parts = s.Split('/');
// use parts[0] and parts[1]

-Brock
DevelopMentor
http://staff.develop.com/ballen


VAR1 = 3/4
VAR2 = 2
I user can submit the values "3/4" or "2" (VAR1, VAR2 represent any
numbers)
when user submits "3/4" we assume 1sthalf/2ndhalf
These values are saved into database as a row
row1: 3/4
row2: 2
I have a datagrid that displays values just fine, but user wants to
beable
to click on the 3 or 4 when we have a "/" in the value.
How do I split the value when it finds a "/" ,
then create a button column(for an event) for each value. This would
allow
the user to click the 3 "or" 4 in 3/4 and then i could run an event
based on
what they clicked.
so,
I was thinking
<a href="p.aspx?id=1sthalf&value=3">3</a> /
<a href="p.aspx?id=2ndhalff&value=4">4</a>
I don't know how to do something like this in the data grid and/or
datalist.
If it doesn't find a "/" it should assume 1sthalf.
Any ideas, hints, HELP would be GREAT!
 
<ItemTemplate>
<asp:Button runat=server CommandName="MyButton" CommandArgument='<%# GetLeftHalf(Container.DataItem)
%>' Text="LeftHalf" />
<asp:Button runat=server CommandName="MyButton" CommandArgument='<%# GetRightHalf(Container.DataItem)
%>' Text="RightHalf" />
</ItemTemplate>

Where GetLeftHalf:

string GetLeftHalf(object data)
{
string s= (string)data;
return s.Split('/')[0]; // do better error checking that i am here :)
}

Then to handle the click handle the DataGrid's ItemCommand event:

void Grid_ItemCommand(object s, DataGridCommandEventArgs e)
{
if (e.CommandName == "MyButton")
{
string theNumber = e.CommandArgument;
/// and so on...
}
}

This is very rough as it's off the top of my head, but I think it should
get you started in the right direction.

-Brock
DevelopMentor
http://staff.develop.com/ballen


Yes, but how do I make that work inside the datagrid ?

Brock Allen said:
string s = "3/4";
string[] parts = s.Split('/');
// use parts[0] and parts[1]
-Brock
DevelopMentor
http://staff.develop.com/ballen
VAR1 = 3/4
VAR2 = 2
I user can submit the values "3/4" or "2" (VAR1, VAR2 represent any
numbers)
when user submits "3/4" we assume 1sthalf/2ndhalf
These values are saved into database as a row
row1: 3/4
row2: 2
I have a datagrid that displays values just fine, but user wants to
beable
to click on the 3 or 4 when we have a "/" in the value.
How do I split the value when it finds a "/" ,
then create a button column(for an event) for each value. This
would
allow
the user to click the 3 "or" 4 in 3/4 and then i could run an event
based on
what they clicked.
so,
I was thinking
<a href="p.aspx?id=1sthalf&value=3">3</a> /
<a href="p.aspx?id=2ndhalff&value=4">4</a>
I don't know how to do something like this in the data grid and/or
datalist.
If it doesn't find a "/" it should assume 1sthalf.
Any ideas, hints, HELP would be GREAT!
 
This works, but it how do I remove one of them when it only has 1 number and
not 2?
so If i have 3/4 it works, but what about if I have 1 or 10
It seems I will have an extra button.


Brock Allen said:
<ItemTemplate>
<asp:Button runat=server CommandName="MyButton" CommandArgument='<%# GetLeftHalf(Container.DataItem)
%>' Text="LeftHalf" />
<asp:Button runat=server CommandName="MyButton" CommandArgument='<%# GetRightHalf(Container.DataItem)
%>' Text="RightHalf" />
</ItemTemplate>

Where GetLeftHalf:

string GetLeftHalf(object data)
{
string s= (string)data;
return s.Split('/')[0]; // do better error checking that i am here :)
}

Then to handle the click handle the DataGrid's ItemCommand event:

void Grid_ItemCommand(object s, DataGridCommandEventArgs e)
{
if (e.CommandName == "MyButton")
{
string theNumber = e.CommandArgument;
/// and so on...
}
}

This is very rough as it's off the top of my head, but I think it should
get you started in the right direction.

-Brock
DevelopMentor
http://staff.develop.com/ballen


Yes, but how do I make that work inside the datagrid ?

Brock Allen said:
string s = "3/4";
string[] parts = s.Split('/');
// use parts[0] and parts[1]
-Brock
DevelopMentor
http://staff.develop.com/ballen
VAR1 = 3/4
VAR2 = 2
I user can submit the values "3/4" or "2" (VAR1, VAR2 represent any
numbers)
when user submits "3/4" we assume 1sthalf/2ndhalf
These values are saved into database as a row
row1: 3/4
row2: 2
I have a datagrid that displays values just fine, but user wants to
beable
to click on the 3 or 4 when we have a "/" in the value.
How do I split the value when it finds a "/" ,
then create a button column(for an event) for each value. This
would
allow
the user to click the 3 "or" 4 in 3/4 and then i could run an event
based on
what they clicked.
so,
I was thinking
<a href="p.aspx?id=1sthalf&value=3">3</a> /
<a href="p.aspx?id=2ndhalff&value=4">4</a>
I don't know how to do something like this in the data grid and/or
datalist.
If it doesn't find a "/" it should assume 1sthalf.
Any ideas, hints, HELP would be GREAT!
 
You can always add/remove items to the row in the ItemDataBound event of
the grid. In that even you have access to DataGridItemEventArgs.Item so you
can add new controls to use FindContorl to remove or hide existing controls.

-Brock
DevelopMentor
http://staff.develop.com/ballen


This works, but it how do I remove one of them when it only has 1
number and
not 2?
so If i have 3/4 it works, but what about if I have 1 or 10
It seems I will have an extra button.
Brock Allen said:
<ItemTemplate>

<asp:Button runat=server CommandName="MyButton" CommandArgument='<%#
GetLeftHalf(Container.DataItem)

%>' Text="LeftHalf" />

<asp:Button runat=server CommandName="MyButton" CommandArgument='<%#
GetRightHalf(Container.DataItem)

%>' Text="RightHalf" />

</ItemTemplate>

Where GetLeftHalf:

string GetLeftHalf(object data)
{
string s= (string)data;
return s.Split('/')[0]; // do better error checking that i am here :)
}
Then to handle the click handle the DataGrid's ItemCommand event:

void Grid_ItemCommand(object s, DataGridCommandEventArgs e)
{
if (e.CommandName == "MyButton")
{
string theNumber = e.CommandArgument;
/// and so on...
}
}
This is very rough as it's off the top of my head, but I think it
should get you started in the right direction.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Yes, but how do I make that work inside the datagrid ?

:

string s = "3/4";
string[] parts = s.Split('/');
// use parts[0] and parts[1]
-Brock
DevelopMentor
http://staff.develop.com/ballen
VAR1 = 3/4
VAR2 = 2
I user can submit the values "3/4" or "2" (VAR1, VAR2 represent
any
numbers)
when user submits "3/4" we assume 1sthalf/2ndhalf
These values are saved into database as a row
row1: 3/4
row2: 2
I have a datagrid that displays values just fine, but user wants
to
beable
to click on the 3 or 4 when we have a "/" in the value.
How do I split the value when it finds a "/" ,
then create a button column(for an event) for each value. This
would
allow
the user to click the 3 "or" 4 in 3/4 and then i could run an
event
based on
what they clicked.
so,
I was thinking
<a href="p.aspx?id=1sthalf&value=3">3</a> /
<a href="p.aspx?id=2ndhalff&value=4">4</a>
I don't know how to do something like this in the data grid and/or
datalist.
If it doesn't find a "/" it should assume 1sthalf.
Any ideas, hints, HELP would be GREAT!
 
Back
Top