Solved

asp.net c#

Posted on 2011-03-07
3
222 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

Independent Software Vendors: 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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled

763 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