?
Solved

asp.net c#

Posted on 2011-03-07
3
Medium Priority
?
228 Views
Last Modified: 2012-05-11
When View Details link is clicked, I want to raise some command..
like response.write "hello"....as an example.
How to do it?

<asp:GridView ID="CustomersView" DataSourceID="Customers"
AutoGenerateColumns="False" AllowSorting="true" AllowPaging="true" PageSize="10"
DataKeyNames="Scheduleid" EmptyDataText="No transaction" runat="server"    
        CellPadding="3" GridLines="Horizontal" 
        >
<HeaderStyle BackColor="Maroon" ForeColor="White" />
<Columns>
<asp:BoundField Visible="false" DataField="scheduleid" HeaderText="Schedule id" ReadOnly="True" SortExpression="scheduleid" />
<asp:BoundField DataField="CustName" HeaderText="Custmer Name" SortExpression="CustName" />
<asp:BoundField DataField="meetinglocation" HeaderText="Meeting Location" SortExpression="meetinglocation" />
<asp:BoundField DataField="Begindate" HeaderText="Begin Date" dataformatstring="{0:MM-dd-yyyy}" SortExpression="Begindate" />
<asp:CommandField ShowSelectButton="True"  SelectText="&nbsp;View Details&nbsp;"/>
</Columns>
</asp:GridView>

Open in new window

0
Comment
Question by:Webboy2008
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 13

Expert Comment

by:Rahul Agarwal
ID: 35065919
Try this Code:


Code Behind:

protected void GridView1_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
      
      try {
if (e.Row.RowType == DataControlRowType.DataRow) {
      e.Row.Controls(3).Visible = false;
      LinkButton lnkBtn = (LinkButton)e.Row.Cells(5).Controls(0);
      lnkBtn.Attributes.Add("onclick", "return confirm('Are you sure you want to delete?');");
}
} catch (Exception ee) {
            lblmsg.Text = ee.Message.ToString();
      }
0
 
LVL 5

Accepted Solution

by:
karthitron earned 2000 total points
ID: 35066072
Hi, use GridView's OnSelectedIndexChanging to find the current selected row index and this event fires when we select a row in the grid and you have also set the "SelectText" as "View Details". So, if user cllicks on the "View Details" link, row get selected, and during the selection changing, OnSelectedIndexChanging event will fire and you can get current selected row details using "GridViewSelectEventArgs" argument. Following is the sample code available in msdn: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.selectedindexchanged.aspx#Y776
void CustomersGridView_SelectedIndexChanging(Object sender, GridViewSelectEventArgs e)
  {

    // Get the currently selected row. Because the SelectedIndexChanging event
    // occurs before the select operation in the GridView control, the
    // SelectedRow property cannot be used. Instead, use the Rows collection
    // and the NewSelectedIndex property of the e argument passed to this 
    // event handler.
    GridViewRow row = CustomersGridView.Rows[e.NewSelectedIndex];

    // You can cancel the select operation by using the Cancel
    // property. For this example, if the user selects a customer with 
    // the ID "ANATR", the select operation is canceled and an error message
    // is displayed.
    if (row.Cells[1].Text == "ANATR")
    {

      e.Cancel = true;
      MessageLabel.Text = "You cannot select " + row.Cells[2].Text + ".";

    }

Open in new window

0
 
LVL 11

Expert Comment

by:SAMIR BHOGAYTA
ID: 35066189
Hi, you have to use javascript alert box for it.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

718 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