Asp.net GridView Enabling row selection

meepy

New Member
I am using GridView in asp.net. I want to select a single data row. I looked for MultiSelect and SelectionMode in property panel, but I can't find it. So how to enable selecting rows in GridView? Thanks.
6jJ7Q.jpg
Code Behind\[code\]public partial class SearchCourse : System.Web.UI.Page{Connection dbCon;DataTable tbl;protected void Page_Load(object sender, EventArgs e){ dbCon = new Connection();}protected void RadioButton1_CheckedChanged(object sender, EventArgs e){ if (RadioButton1.Checked) { txtSubName.Enabled = true; comboSemester.Enabled = false; comboYear.Enabled = false; comboProgram.Enabled =false; txtSubName.Text = ""; }}protected void RadioButton2_CheckedChanged(object sender, EventArgs e){ if (RadioButton2.Checked) { comboProgram.Enabled = true; if (comboProgram.SelectedItem.ToString() == "Foundation Course") { comboSemester.Enabled = false; comboYear.Enabled = false; } else { comboSemester.Enabled = true; comboYear.Enabled = true; } txtSubName.Text = ""; txtSubName.Enabled = false; }}protected void imgBtnSearch_Click(object sender, ImageClickEventArgs e){ if (RadioButton1.Checked) { String name = txtSubName.Text; tbl = dbCon.getResultsBySubjectName(name); GridView1.DataSource = tbl; GridView1.DataBind(); } else if (RadioButton2.Checked) { String program = comboProgram.SelectedItem.ToString(); String year = comboYear.SelectedItem.ToString(); String sem= comboSemester.SelectedItem.ToString(); tbl = dbCon.getResultsByProgram(program,year,sem); GridView1.DataSource = tbl; GridView1.DataBind(); } else if (RadioButton3.Checked) { String name = txtSubName.Text; tbl = dbCon.getResultsBySubjectNo(name); GridView1.DataSource = tbl; GridView1.DataBind(); }}protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e){ String program = comboProgram.SelectedItem.ToString(); String year, sem; if (program == "Foundation Course") { comboYear.Enabled = false; comboSemester.Enabled = false; year = null; sem = null; } else { comboYear.Enabled = true; comboSemester.Enabled = true; year = comboYear.SelectedItem.ToString(); sem = comboSemester.SelectedItem.ToString(); } tbl = dbCon.getResultsByProgram(program, year, sem); GridView1.DataSource = tbl; GridView1.DataBind();}protected void comboYear_SelectedIndexChanged(object sender, EventArgs e){ String program = comboProgram.SelectedItem.ToString(); String year = comboYear.SelectedItem.ToString(); String sem = comboSemester.SelectedItem.ToString(); tbl = dbCon.getResultsByProgram(program, year, sem); GridView1.DataSource = tbl; GridView1.DataBind();}protected void comboSemester_SelectedIndexChanged(object sender, EventArgs e){ String program = comboProgram.SelectedItem.ToString(); String year = comboYear.SelectedItem.ToString(); String sem = comboSemester.SelectedItem.ToString(); tbl = dbCon.getResultsByProgram(program, year, sem); GridView1.DataSource = tbl; GridView1.DataBind();}protected void RadioButton3_CheckedChanged(object sender, EventArgs e){ if (RadioButton3.Checked) { txtSubName.Enabled = true; comboSemester.Enabled = false; comboYear.Enabled = false; comboProgram.Enabled = false; txtSubName.Text = ""; }}protected void GridView1_SelectedIndexChanged(object sender, EventArgs e){}\[/code\]}GridView Code \[code\]<asp:GridView ID="GridView1" CssClass="grid" runat="server" AllowPaging="True" BorderColor="Black" BorderStyle="Solid" BorderWidth="2px" GridLines="Horizontal" EnableViewState="False" PageSize="5" onselectedindexchanged="GridView1_SelectedIndexChanged" >\[/code\]\[code\]<RowStyle CssClass="gridRow" Width="800px" /><SelectedRowStyle BackColor="#FF0066" ForeColor="White" /></asp:GridView> \[/code\]
 
Back
Top