Solved

Gridview Coding issue  - EditItemTemplate

Posted on 2013-01-24
12
362 Views
Last Modified: 2013-01-27
I have a gridview which displays data regarding tasks assigned to various people, within the grid I have setup a template within the 'Resource' field, which reads a list of Resources from another table and then lets me choose a resource to update the table which is displaying the data in the gridview.
What I would like to do is, when a resource is selected from the drop down, I want an event to fire that will send an email to that resource, I have the code for sending the email and also the code for selecting the email address, my issue is how can I bind this to this type of control ? Or is there a better way to do this ?
0
Comment
Question by:ndr-itsolutions
12 Comments
 
LVL 41

Expert Comment

by:guru_sami
ID: 38816671
Do you want to send an email as soon as the resource is selected in the dropdown or only when user Submit the update changes?
0
 

Author Comment

by:ndr-itsolutions
ID: 38816730
When the user submits the updated changes.
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 38816738
You can do that in the RowCommand or RowUpdate Event handler.
It will be a single row update right or you have multiple row updates at a single time?
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:ndr-itsolutions
ID: 38816758
Yes, a single row.

Any example code ?
0
 
LVL 41

Accepted Solution

by:
guru_sami earned 500 total points
ID: 38816822
It would be something like this:

protected void GridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{
        string resource = e.NewValues[1].ToString(); //1 is the index for your resource column
        //the row was updated and you can send your email here.
}
0
 
LVL 10

Expert Comment

by:Monica P
ID: 38817617
http://www.codeproject.com/Questions/163877/Row-updating-event-in-gridview-ASP-NET

http://stackoverflow.com/questions/987980/getting-a-selected-value-from-the-drop-down-list-inside-a-gridview-on-update

try to find the control under RowUpdated event


try something like this

protected void gv_UpdateRow(string arg)
{
    int currentIndex = gv.EditIndex;
    gv.EditIndex = -1;

    GridViewRow currentRow = gv.Rows[currentIndex];

    try
    {
      string value2 = ((DropDownList)currentRow.FindControl("ddlValueTwo")).SelectedItem.ToString();
//Place your email code here and test 
    }
    catch
    {
        Response.Write("error");
    }


    BindGridView(); 
}

Open in new window


GEt DDL selected value in gridview

http://www.dotnetfunda.com/codes/code3389-how-to-get-dropdownlist-selected-value-in-inside-gridview-in-aspnet.aspx
http://stackoverflow.com/questions/5000489/how-to-edit-and-update-row-values-in-grid-view
0
 

Author Comment

by:ndr-itsolutions
ID: 38817739
Sorry should have said, I'm using vb.net
0
 
LVL 20

Expert Comment

by:informaniac
ID: 38817980
Here, use this

http://converter.telerik.com/
Protected Sub gv_UpdateRow(arg As String)
	Dim currentIndex As Integer = gv.EditIndex
	gv.EditIndex = -1

	Dim currentRow As GridViewRow = gv.Rows(currentIndex)

	Try
			'Place your email code here and test 
		Dim value2 As String = DirectCast(currentRow.FindControl("ddlValueTwo"), DropDownList).SelectedItem.ToString()
	Catch
		Response.Write("error")
	End Try


	BindGridView()
End Sub

'=======================================================
'Service provided by Telerik (www.telerik.com)
'Conversion powered by NRefactory.
'Twitter: @telerik, @toddanglin
'Facebook: facebook.com/telerik
'=======================================================

Open in new window

0
 

Author Comment

by:ndr-itsolutions
ID: 38818247
So where would I insert this code ?
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 38820712
Can you tell what code you are trying to use? Did you follow the links posted?
The basic idea is handle your GridView's RowUpdated event.
0
 

Author Comment

by:ndr-itsolutions
ID: 38823745
I'm looking to use the first suggestion

 Dim resource As String = e.NewValues(1).ToString()
        '1 is the index for your resource column
        'the row was updated and you can send your email here.

I've placed it in the code behind of the web form that contains the gridview.
0
 

Author Closing Comment

by:ndr-itsolutions
ID: 38824997
This worked a treat after I worked out that I had not added my sub routine to the gridview.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question