Showing posts with label byval. Show all posts
Showing posts with label byval. Show all posts

Saturday, March 31, 2012

Substitue ItemArray with something else in a FormView

When loading a FormView I try to fill a third-party combo control with
this code:
Protected Sub FormView1_ItemCreated(ByVal sender As Object, ByVal e As
EventArgs)
If FormView1.Row.RowState = DataControlRowState.Edit Then
Dim rowView As DataRowView = TryCast(FormView1.DataItem,
DataRowView)
If Not rowView Is Nothing Then
'Get and fill cboProject
Dim strProjectID As String =
TryCast(rowView.Row.ItemArray(8), String)
Dim cboProject As WebCombo =
TryCast(FormView1.FindControl("cboProject"), WebCombo)
cboProject.Value = strProjectID
End If
End If
End Sub
It works great except that I would like to change
"TryCast(rowView.Row.ItemArray(8), String)" and use the column name
instead of ItemArray(8). I have many columns in the FormView so it's
very difficult for me to guess which number represents a certain
column.
How can this be done?
I'm very grateful for help!
// SHi there,
First of all it's better to move databound-releated code to DataBound event
handler. Second you can access column by names directly from DataRowView:
protected Sub FormView1_DataBound( _
ByVal sender As Object, _
ByVal e As EventArgs)
dim formView as FormView = DirectCast(sender, FormView)
if formView.CurrentMode = FormViewMode.Edit then
Dim rowView As DataRowView = TryCast( _
formView.DataItem, DataRowView)
Dim cboProject as WebCombo = TryCast( _
formView.FindControl("cboProject"), WebControl)
cboProject.Value = Convert.ToString(rowView("ColumnName"))
end if
end sub
Hope this helps
--
Milosz
"staeri@.gmail.com" wrote:

> When loading a FormView I try to fill a third-party combo control with
> this code:
> Protected Sub FormView1_ItemCreated(ByVal sender As Object, ByVal e As
> EventArgs)
> If FormView1.Row.RowState = DataControlRowState.Edit Then
> Dim rowView As DataRowView = TryCast(FormView1.DataItem,
> DataRowView)
> If Not rowView Is Nothing Then
> 'Get and fill cboProject
> Dim strProjectID As String =
> TryCast(rowView.Row.ItemArray(8), String)
> Dim cboProject As WebCombo =
> TryCast(FormView1.FindControl("cboProject"), WebCombo)
> cboProject.Value = strProjectID
> End If
> End If
> End Sub
> It works great except that I would like to change
> "TryCast(rowView.Row.ItemArray(8), String)" and use the column name
> instead of ItemArray(8). I have many columns in the FormView so it's
> very difficult for me to guess which number represents a certain
> column.
> How can this be done?
> I'm very grateful for help!
> // S
>

Thursday, March 22, 2012

supervision on mass e mail sending

i use a loop to send e mail to all my site users, and using this procedure for the work:

Sub Mailshot(ByVal adress As String, ByVal subject As String, ByVal body As String)
Dim msgmail As MailMessage = New MailMessage()

SmtpMail.SmtpServer = "smtp.012.net.il"
msgmail.From = "shoresh@dotnet.itags.org.shoresh.org.il"

Try
msgmail.To = adress
msgmail.Body = body
msgmail.Subject = subject
msgmail.BodyFormat = MailFormat.Html
SmtpMail.Send(msgmail)
Catch exc As Exception
'DO WHATEVER ERROR HANDLING
End Try
msgmail = Nothing
End Sub

my site have something like 1000 users. and i call the sub one by one (for...next loop)

I have two questions about this e mail sending:
1) does this loop is going to overflow? if yes, what should i do to prevent it?
2) do i have any way to supervise the sending progress, i should to refresh the page every time, something that i think is not so good idea!!

thanksA For...Next loop is better suited for what you are trying to acomplish
i do use a for next loop to call the sending procedure. i wondered if this calling again and again wont stuck it.
Can you create a group and put all your users on it and then just send an email to the group?