Solved

asp.net c#

Posted on 2011-03-07
3
223 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:agarwalrahul
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 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Save json data from URL using SSIS 1 72
I need help writing Unit Tests for my ASP.Net MVC application 5 38
Need help for captcha 2 39
What are MicroServices? 4 65
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 …
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

739 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