Error in Select Command of Gridview

Posted by .Netlearner under ASP.NET on 10/30/2012 | Points: 10 | Views : 1120 | Status : [Member] | Replies : 0
hello all,
i have a grid view as follows
 
<asp:GridView ID="gvbatch" runat="server" AutoGenerateColumns="False" OnRowDataBound="gvbatch_RowDataBound"
CellPadding="3" onrowcommand="gvbatch_RowCommand" CssClass="GridViewStyle" Width="100%" Visible="true"
OnSorting="gvbatch_Sorting" OnRowUpdated="oru" OnRowUpdating="orug" OnPageIndexChanging="gvbatch_PageIndexChanging" OnRowEditing="gvbatch_OnRowEditing" OnSelectedIndexChanged="gvbatch_OnSelectedIndexChanged">
<Columns>

<asp:BoundField DataField="BatchID" HeaderText="ID" ItemStyle-Width="40px" ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="BatchName" HeaderText="Batch Name" ItemStyle-Width="200px" ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="CourseID" HeaderText="Course ID" Visible="false" />
<asp:BoundField DataField="CourseType" HeaderText="Course Type" ItemStyle-Width="200px" ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="CourseName" HeaderText="DepartmentID" ItemStyle-Width="200px" ItemStyle-HorizontalAlign="Center"/>
<asp:BoundField DataField="StartTime" HeaderText="Start Time" ItemStyle-Width="200px" ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="EndTime" HeaderText="End Time" ItemStyle-Width="200px" ItemStyle-HorizontalAlign="Center" />
<asp:TemplateField HeaderText="Select" ItemStyle-Width="40px" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Button ID="btnselect" runat="server" CommandName="Select" Text="select" CausesValidation="false" />
</ItemTemplate>
</asp:TemplateField>
</Columns>

</asp:GridView>


on Clicking the select Command i want to display the data from the grid to other controls as follows,

protected void gvbatch_OnSelectedIndexChanged(object sender, EventArgs e)
{
lblBatchName.ToolTip = gvbatch.SelectedRow.Cells[0].Text;
con.Open();
ddlcoursename.Text = gvbatch.SelectedRow.Cells[4].Text;
ddlcoursetype.Text = gvbatch.SelectedRow.Cells[3].Text;
txtbatchname.Text = gvbatch.SelectedRow.Cells[1].Text;
}

But on clicking the select button i get the following error.Can anyone guide me how to solve this.If i used Enable Event Validation="false" in my page directive" error is not coming.But the row is also not selected.How to solve this issue , i want my row to be selected when i click the select button




Responses

(No response found.)

Login to post response