I have following grid view control
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
style="z-index: 1; left: 59px; top: 1px; position: absolute; height: 158px; width: 658px"
BorderColor="#0066FF" BorderStyle="Solid" PageSize="20"
onselectedindexchanged="GridView1_SelectedIndexChanged"
DataKeyNames="application_id">
<PagerSettings NextPageText="Next" PageButtonCount="20" />
<Columns>
<asp:HyperLinkField NavigateUrl="view_forms.aspx"
DataNavigateUrlFormatString=""
DataTextField="application_id" HeaderText="Application ID">
<HeaderStyle Font-Names="Verdana" Font-Size="Small"
HorizontalAlign="Center" />
<ItemStyle Font-Names="Verdana" Font-Size="Small" HorizontalAlign="Center" />
</asp:HyperLinkField>
<asp:BoundField DataField="application_type" HeaderText="Application Type">
<HeaderStyle Font-Names="Verdana" Font-Size="Small" />
<ItemStyle Font-Names="Verdana" Font-Size="Small" HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="applied_date" HeaderText="Applied Date">
<HeaderStyle Font-Names="Verdana" Font-Size="Small" />
<ItemStyle Font-Names="Verdana" Font-Size="Small" HorizontalAlign="Center" />
</asp:BoundField>
</Columns>
<HeaderStyle BackColor="#66CCFF" />
<AlternatingRowStyle BackColor="#C1E0FF" />
</asp:GridView>
and this is the C# class file that contain to event handlers. One of them is bounding the gridview control to datasource and another is handling OnSelectedIndexChanged event fired by grid view.
but this event handler is likely not being called when I click on a DataKey field of a row of Gridview Control.
public partial class pending_forms : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string constring = "Driver={MySQL ODBC 5.1 Driver};server=localhost;uid=root;password=tripathi;database=db_dcii;port=3306";
DataTable dt = new DataTable();
try
{
using (OdbcConnection connection = new OdbcConnection(constring))
{
using (OdbcCommand sqlCmd = new OdbcCommand("Select * from pending_apps", connection))
{
OdbcDataAdapter sqlDa = new OdbcDataAdapter(sqlCmd);
sqlDa.Fill(dt);
if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
}
}
catch (Exception ex)
{
}
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
Session.Add("application_id", GridView1.SelectedValue.ToString());
String str = GridView1.SelectedValue.ToString();
}
}