Solved

asp.net c#

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

758 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

13 Experts available now in Live!

Get 1:1 Help Now