Solved

Gridview Coding issue  - EditItemTemplate

Posted on 2013-01-24
12
360 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
 

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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now