Showing posts with label column. Show all posts
Showing posts with label column. Show all posts

Saturday, March 31, 2012

Subscribing to event from Template Column

I have an ascx control in the ItemTemplate of a Template Column in a
datagrid. The control (myControl) raises an event.

I'm trying to figure out how I can subscribe to the event. It can't be done
at design time because myControl is not one of the recognized controls. At
run time I would expect to use AddHandler but I can't seem to reference
myControl.

How can I subscribe to the event?

Thanks,
THi Tina,

If your control is simply a composite control that is placed declaratively
on the page at design time then you can add the event handler within the ascx
codebehind file.

Alternatively, you can use event delegates to expose events out of your ascx
to its NamingContainer (in your case it is the DataGridItem) as I did in this
example: http://www.societopia.net/Samples/D...tDelegates.aspx

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com

"Tina" wrote:

> I have an ascx control in the ItemTemplate of a Template Column in a
> datagrid. The control (myControl) raises an event.
> I'm trying to figure out how I can subscribe to the event. It can't be done
> at design time because myControl is not one of the recognized controls. At
> run time I would expect to use AddHandler but I can't seem to reference
> myControl.
> How can I subscribe to the event?
> Thanks,
> T
>
I guess I'm going to have to learn c# if for nothing other than to follow
the examples...

in VB to handle an event we ....
AddHandler myControl.TimerEvent, AddressOf me.HandleTimerEvent
..
..
Protected Sub HandleTimerEvent(byval o as Object, byval e as TimerArgs)
.. code to handle event is here...
end sub

How would the AddHandler code look in the case where myControl is in
DataGrid1?

"Phillip Williams" <Phillip.Williams@.webswapp.com> wrote in message
news:0EF5A6EE-2CBF-4FDE-9B9F-148297D8E8CA@.microsoft.com...
> Hi Tina,
> If your control is simply a composite control that is placed declaratively
> on the page at design time then you can add the event handler within the
> ascx
> codebehind file.
> Alternatively, you can use event delegates to expose events out of your
> ascx
> to its NamingContainer (in your case it is the DataGridItem) as I did in
> this
> example: http://www.societopia.net/Samples/D...tDelegates.aspx
> --
> HTH,
> Phillip Williams
> http://www.societopia.net
> http://www.webswapp.com
>
> "Tina" wrote:
>> I have an ascx control in the ItemTemplate of a Template Column in a
>> datagrid. The control (myControl) raises an event.
>>
>> I'm trying to figure out how I can subscribe to the event. It can't be
>> done
>> at design time because myControl is not one of the recognized controls.
>> At
>> run time I would expect to use AddHandler but I can't seem to reference
>> myControl.
>>
>> How can I subscribe to the event?
>>
>> Thanks,
>> T
>>
>>
>
Hi Tina,

For you to be able to handle an event (e.g. TimerEvent) raised by your
control it has to define a delegate method that you can use when placing that
control in the DataGrid. If it does that then you can handle that event by
specifying a function for the delegate method (e.g. if your event is named
TimerEvent, you should design your control to expose a method named
OnTimerEvent)

I created here
http://www.societopia.net/Samples/D...rolsEvents.aspx a sample
in VB.Net where I designed a user control (in an ascx file) that raises an
event (I called it CustomEvent1) by exposing a delegate method called
"OnCustomEvent1". I then included that control in a TemplateColumn on the
DataGrid and wired the delegate function named OnCustomEvents to an event
handler within the page class codebehind.

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com

"Tina" wrote:

> I guess I'm going to have to learn c# if for nothing other than to follow
> the examples...
> in VB to handle an event we ....
> AddHandler myControl.TimerEvent, AddressOf me.HandleTimerEvent
> ..
> ..
> Protected Sub HandleTimerEvent(byval o as Object, byval e as TimerArgs)
> .. code to handle event is here...
> end sub
> How would the AddHandler code look in the case where myControl is in
> DataGrid1?
> "Phillip Williams" <Phillip.Williams@.webswapp.com> wrote in message
> news:0EF5A6EE-2CBF-4FDE-9B9F-148297D8E8CA@.microsoft.com...
> > Hi Tina,
> > If your control is simply a composite control that is placed declaratively
> > on the page at design time then you can add the event handler within the
> > ascx
> > codebehind file.
> > Alternatively, you can use event delegates to expose events out of your
> > ascx
> > to its NamingContainer (in your case it is the DataGridItem) as I did in
> > this
> > example: http://www.societopia.net/Samples/D...tDelegates.aspx
> > --
> > HTH,
> > Phillip Williams
> > http://www.societopia.net
> > http://www.webswapp.com
> > "Tina" wrote:
> >> I have an ascx control in the ItemTemplate of a Template Column in a
> >> datagrid. The control (myControl) raises an event.
> >>
> >> I'm trying to figure out how I can subscribe to the event. It can't be
> >> done
> >> at design time because myControl is not one of the recognized controls.
> >> At
> >> run time I would expect to use AddHandler but I can't seem to reference
> >> myControl.
> >>
> >> How can I subscribe to the event?
> >>
> >> Thanks,
> >> T
> >>
> >>
> >>
>

Subscribing to event from Template Column

I have an ascx control in the ItemTemplate of a Template Column in a
datagrid. The control (myControl) raises an event.
I'm trying to figure out how I can subscribe to the event. It can't be done
at design time because myControl is not one of the recognized controls. At
run time I would expect to use AddHandler but I can't seem to reference
myControl.
How can I subscribe to the event?
Thanks,
THi Tina,
If your control is simply a composite control that is placed declaratively
on the page at design time then you can add the event handler within the asc
x
codebehind file.
Alternatively, you can use event delegates to expose events out of your ascx
to its NamingContainer (in your case it is the DataGridItem) as I did in thi
s
example: http://www.societopia.net/Samples/D...tDelegates.aspx
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Tina" wrote:

> I have an ascx control in the ItemTemplate of a Template Column in a
> datagrid. The control (myControl) raises an event.
> I'm trying to figure out how I can subscribe to the event. It can't be do
ne
> at design time because myControl is not one of the recognized controls. A
t
> run time I would expect to use AddHandler but I can't seem to reference
> myControl.
> How can I subscribe to the event?
> Thanks,
> T
>
>
I guess I'm going to have to learn c# if for nothing other than to follow
the examples...
in VB to handle an event we ....
AddHandler myControl.TimerEvent, AddressOf me.HandleTimerEvent
.
.
Protected Sub HandleTimerEvent(byval o as Object, byval e as TimerArgs)
. code to handle event is here...
end sub
How would the AddHandler code look in the case where myControl is in
DataGrid1?
"Phillip Williams" <Phillip.Williams@.webswapp.com> wrote in message
news:0EF5A6EE-2CBF-4FDE-9B9F-148297D8E8CA@.microsoft.com...
> Hi Tina,
> If your control is simply a composite control that is placed declaratively
> on the page at design time then you can add the event handler within the
> ascx
> codebehind file.
> Alternatively, you can use event delegates to expose events out of your
> ascx
> to its NamingContainer (in your case it is the DataGridItem) as I did in
> this
> example: http://www.societopia.net/Samples/D...tDelegates.aspx
> --
> HTH,
> Phillip Williams
> http://www.societopia.net
> http://www.webswapp.com
>
> "Tina" wrote:
>
Hi Tina,
For you to be able to handle an event (e.g. TimerEvent) raised by your
control it has to define a delegate method that you can use when placing tha
t
control in the DataGrid. If it does that then you can handle that event by
specifying a function for the delegate method (e.g. if your event is named
TimerEvent, you should design your control to expose a method named
OnTimerEvent)
I created here
http://www.societopia.net/Samples/D...rolsEvents.aspx a sampl
e
in VB.Net where I designed a user control (in an ascx file) that raises an
event (I called it CustomEvent1) by exposing a delegate method called
“OnCustomEvent1”. I then included that control in a TemplateColumn on t
he
DataGrid and wired the delegate function named OnCustomEvents to an event
handler within the page class codebehind.
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Tina" wrote:

> I guess I'm going to have to learn c# if for nothing other than to follow
> the examples...
> in VB to handle an event we ....
> AddHandler myControl.TimerEvent, AddressOf me.HandleTimerEvent
> ..
> ..
> Protected Sub HandleTimerEvent(byval o as Object, byval e as TimerArgs)
> .. code to handle event is here...
> end sub
> How would the AddHandler code look in the case where myControl is in
> DataGrid1?
> "Phillip Williams" <Phillip.Williams@.webswapp.com> wrote in message
> news:0EF5A6EE-2CBF-4FDE-9B9F-148297D8E8CA@.microsoft.com...
>
>

Wednesday, March 28, 2012

Substitute Values in Column in Gridview

I have a Gridview bound to an SQLDataSource (see code below). The value of
the "DayOfWeek" column is actually an integer where 0 = Daily, 1=Sunday,
2=Monday, etc. How can I change what is displayed in the column from values
like 1or 2 to "Sunday", "Monday"?

============== Code =================
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True"

AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
<Columns
<asp:BoundField DataField="EventName" HeaderText="EventName"
SortExpression="EventName" /
<asp:BoundField DataField="DayOfWeek" HeaderText="DayOfWeek"
SortExpression="DayOfWeek" /
<asp:BoundField DataField="Occurs" HeaderText="Occurs"
SortExpression="Occurs" /
<asp:BoundField DataField="Location" HeaderText="Location"
SortExpression="Location" /
</Columns
</asp:GridViewI finally found an example that I could apply. I created a Select Case
function named GetDayOfWeek to return the string I wanted for each case and
then replaced the Bound Column in the ASP code to:

<asp:TemplateField HeaderText="Day of Week"
<ItemTemplate
<%#GetDayOfWeek(CInt(Eval("DayOfWeek")))%
</ItemTemplate
</asp:TemplateField
Wayne

"Wayne Wengert" <wayneSKIPSPAM@.wengert.org> wrote in message
news:ut%232Q9SRGHA.4696@.tk2msftngp13.phx.gbl...
>I have a Gridview bound to an SQLDataSource (see code below). The value of
>the "DayOfWeek" column is actually an integer where 0 = Daily, 1=Sunday,
>2=Monday, etc. How can I change what is displayed in the column from values
>like 1or 2 to "Sunday", "Monday"?
>
> ============== Code =================
> <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
> AllowSorting="True"
> AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
> <Columns>
> <asp:BoundField DataField="EventName" HeaderText="EventName"
> SortExpression="EventName" />
> <asp:BoundField DataField="DayOfWeek" HeaderText="DayOfWeek"
> SortExpression="DayOfWeek" />
> <asp:BoundField DataField="Occurs" HeaderText="Occurs"
> SortExpression="Occurs" />
> <asp:BoundField DataField="Location" HeaderText="Location"
> SortExpression="Location" />
> </Columns>
> </asp:GridView>

Monday, March 26, 2012

Suggestion for generating unique identifier.

Anyone have any suggestions for generating a unique identifier for a DB
column. I don't want to use an IDENTITY column because two seperate tables
will have PK columns that cannot have duplicate key values amongst the
tables. I thought about something to do with Date/Time. It can be any
datatype for that matter, it does not have to be an int type. I just need
something to uniquely identify records from two seperate tables.
Thanks
Marty UMarty U. <Marty U.@.discussions.microsoft.com> typed:
> Anyone have any suggestions for generating a unique identifier for a
> DB column. I don't want to use an IDENTITY column because two
> seperate tables will have PK columns that cannot have duplicate key
> values amongst the tables. I thought about something to do with
> Date/Time. It can be any datatype for that matter, it does not have
> to be an int type. I just need something to uniquely identify records
> from two seperate tables.
> Thanks
> Marty U
You could use a GUID. In C#:
string myGuid = Guid.NewGuid().ToString();
Davide Vernole
MVP ASP/ASP.NET
Microsoft Certified Solution Developer
GUID
SQL Server datatype "uniqueidentifier"
Greg
"Marty U." <Marty U.@.discussions.microsoft.com> wrote in message
news:D6C67BD9-3AA6-4125-9F4D-E16C63E94A89@.microsoft.com...
> Anyone have any suggestions for generating a unique identifier for a DB
> column. I don't want to use an IDENTITY column because two seperate tables
> will have PK columns that cannot have duplicate key values amongst the
> tables. I thought about something to do with Date/Time. It can be any
> datatype for that matter, it does not have to be an int type. I just need
> something to uniquely identify records from two seperate tables.
> Thanks
> Marty U
Marty U. wrote:
> Anyone have any suggestions for generating a unique identifier for a DB
> column. I don't want to use an IDENTITY column because two seperate tables
> will have PK columns that cannot have duplicate key values amongst the
> tables. I thought about something to do with Date/Time. It can be any
> datatype for that matter, it does not have to be an int type. I just need
> something to uniquely identify records from two seperate tables.
>
GUIDs are often used for that:
Guid id = Guid.NewGuid();
this corresponds to SQL Server's UniqueIdentifier type.
The SQL server can generate one using the NEWID() function - you can set
the column's default value to NEWID() to have the GUID generated
automatically for new records.
mikeb

Saturday, March 24, 2012

Suggestions on how to Open a New Window from a data grid

I have a datagrid that holds a whole list of records about computers. I need
one column that is a hyperlink that when clicked will show the details of t
hat computer model. The hyper link needs to open in a new window and have an
address that is my page na
me (modelinfo.aspx). That part is easy, as this is built into the datagrid c
ontrol. But the last thing I need is a varible on it, so when the hyperlink
is clicked, a New page would open and have an address "modelinfo.aspx?Model=
" & what ever value is in t
he corresponding cell that was clicked. So if I clicked on Model "e20" the a
ddress bar would have to read "modelinfo.aspx?Model=e20" etc. Any suggesti
ons? Thanks
Billtry this in the datagrid..
<asp:HyperLink runat="server" Target=_blank Text='<%#
DataBinder.Eval(Container, "DataItem.Model") %>' NavigateUrl='<%#
DataBinder.Eval(Container, "DataItem.Model", "modelinfo.aspx?Model={0}"
)
%>'></asp:HyperLink>
Av.
"Bill" <anonymous@.discussions.microsoft.com> wrote in message
news:37BAE768-6513-47BE-AD69-4DC4903D4573@.microsoft.com...
>I have a datagrid that holds a whole list of records about computers. I
>need one column that is a hyperlink that when clicked will show the details
>of that computer model. The hyper link needs to open in a new window and
>have an address that is my page name (modelinfo.aspx). That part is easy,
>as this is built into the datagrid control. But the last thing I need is a
>varible on it, so when the hyperlink is clicked, a New page would open and
>have an address "modelinfo.aspx?Model=" & what ever value is in the
>corresponding cell that was clicked. So if I clicked on Model "e20" the
>address bar would have to read "modelinfo.aspx?Model=e20" etc. Any
>suggestions? Thanks
> Bill

Suggestions on how to Open a New Window from a data grid

I have a datagrid that holds a whole list of records about computers. I need one column that is a hyperlink that when clicked will show the details of that computer model. The hyper link needs to open in a new window and have an address that is my page name (modelinfo.aspx). That part is easy, as this is built into the datagrid control. But the last thing I need is a varible on it, so when the hyperlink is clicked, a New page would open and have an address "modelinfo.aspx?Model=" & what ever value is in the corresponding cell that was clicked. So if I clicked on Model "e20" the address bar would have to read "modelinfo.aspx?Model=e20" etc. Any suggestions? Thank

Billtry this in the datagrid..

<asp:HyperLink runat="server" Target=_blank Text='<%#
DataBinder.Eval(Container, "DataItem.Model") %>' NavigateUrl='<%#
DataBinder.Eval(Container, "DataItem.Model", "modelinfo.aspx?Model={0}")
%>'></asp:HyperLink
Av.

"Bill" <anonymous@.discussions.microsoft.com> wrote in message
news:37BAE768-6513-47BE-AD69-4DC4903D4573@.microsoft.com...
>I have a datagrid that holds a whole list of records about computers. I
>need one column that is a hyperlink that when clicked will show the details
>of that computer model. The hyper link needs to open in a new window and
>have an address that is my page name (modelinfo.aspx). That part is easy,
>as this is built into the datagrid control. But the last thing I need is a
>varible on it, so when the hyperlink is clicked, a New page would open and
>have an address "modelinfo.aspx?Model=" & what ever value is in the
>corresponding cell that was clicked. So if I clicked on Model "e20" the
>address bar would have to read "modelinfo.aspx?Model=e20" etc. Any
>suggestions? Thanks
> Bill

sum of column in footer

Is there a way to sum all the columns values in a gridview and show it in
the footer of that column? anyone try this before? thanks!Hi,
you can do it by handling RowRataBound event of the GridView. Calculate sums
in it (as it's repeated for every row) and when GridViewRow's RowType is
Footer, place the sum value into it (for example by using a TemplateField
having Label in footer to which you set the sum, as it's Text value)
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
"Smokey Grindle" <nospamhere@.dontspam.net> wrote in message
news:efKT5aInGHA.4352@.TK2MSFTNGP02.phx.gbl...
> Is there a way to sum all the columns values in a gridview and show it in
> the footer of that column? anyone try this before? thanks!
>
hello smokey
here's a working code example. hope it helps
http://authors.aspalliance.com/aspx...wdatabound.aspx
hello smokey
here's a working code example. hope it helps
http://authors.aspalliance.com/aspx...wdatabound.aspx
thanks everyone!
"ReyN" <rvnunez@.yahoo.com> wrote in message
news:1151736818.909778.118790@.m79g2000cwm.googlegroups.com...
> hello smokey
> here's a working code example. hope it helps
> http://authors.aspalliance.com/aspx...wdatabound.aspx
>

sum of column in footer

Is there a way to sum all the columns values in a gridview and show it in
the footer of that column? anyone try this before? thanks!Hi,

you can do it by handling RowRataBound event of the GridView. Calculate sums
in it (as it's repeated for every row) and when GridViewRow's RowType is
Footer, place the sum value into it (for example by using a TemplateField
having Label in footer to which you set the sum, as it's Text value)

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
"Smokey Grindle" <nospamhere@.dontspam.net> wrote in message
news:efKT5aInGHA.4352@.TK2MSFTNGP02.phx.gbl...
> Is there a way to sum all the columns values in a gridview and show it in
> the footer of that column? anyone try this before? thanks!
>
hello smokey

here's a working code example. hope it helps

http://authors.aspalliance.com/aspx...wdatabound.aspx
hello smokey

here's a working code example. hope it helps

http://authors.aspalliance.com/aspx...wdatabound.aspx
thanks everyone!

"ReyN" <rvnunez@.yahoo.com> wrote in message
news:1151736818.909778.118790@.m79g2000cwm.googlegr oups.com...
>
> hello smokey
>
> here's a working code example. hope it helps
>
> http://authors.aspalliance.com/aspx...wdatabound.aspx
>

Sum result in Label field

I summed a column of numbers and would like to put them in a Label field to display the result. I understand the conversion for number to string, I don't understand how to that value, that has been summed, to do it.

thanks
grady

int x = 7;
int y = 7;
int z = x + y;

LabelID.Text = z.ToString();

Is that what you're looking for?

HTH,
Ryan


Actually I have summed a column called TFsum and I was trying to display that and it say it was undeclared.

Here is the SQL:
SELECT SUM(filesfailed) AS TFsum
FROM accmonreport
WHERE oa='ddlOA'
HAVING SUM(filesfailed)=0

ddlOA is a dropdown list in the first view on the page. I'm just to get the variable TFsum to do some calculations.

thanks
grady


Could you post the relevent code?

Ryan


All I'm trying now is get the TFsum value into the lblcompliant label.

thanks
grady

Imports System.Data
Imports System.Data.OleDB
Imports System.Data.OleDb.OleDbDataReader

Partial Class reports_508report
Inherits System.Web.UI.Page

Protected Sub SubmitBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs)

If (Page.IsValid) Then

Dim ddlOA As String = ddloalist.SelectedValue

Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
"c:\accmon\database\accmon.mdb" & ";"
Dim MySQL As String = "SELECT SUM(filesfailed)AS TFsum FROM accmonreport WHERE oa='ddlOA' HAVING filesfailed=0"
Dim MyConn As New OleDbConnection(strConn)
Dim cmd As New OleDbCommand(MySQL, MyConn)
MyConn.Open()
cmd.ExecuteReader()
MyConn.Close()

lblCompliant.Text = " "

OAReport.SetActiveView(Result)
End If

End Sub

End Class


You need to make a couple of changes.

If (Page.IsValid) Then

Dim ddlOA As String = ddloalist.SelectedValue

Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
"c:\accmon\database\accmon.mdb" & ";"
Dim MySQL As String = "SELECT SUM(filesfailed)AS TFsum FROM accmonreport WHERE oa='" & ddlOA & "' HAVING filesfailed=0"
Dim reader As OleDbDataReader
Dim MyConn As New OleDbConnection(strConn)
Dim cmd As New OleDbCommand(MySQL, MyConn)
MyConn.Open()
reader =cmd.ExecuteReader()

While reader.Read()
lblCompliant.Text = reader("TFsum")
End While

reader.Close()
MyConn.Close()

OAReport.SetActiveView(Result)
End If

HTH,
Ryan


Thanks, I really appreciate your time and knowledge. If you don't mind, I have one more question. In Coldfusion there is a function that gives me a recordcount after every query. How do you implement something like that in .Net?

thanks
grady