Asp.net GridView Enabling row selection -
i using gridview in asp.net. want select single data row. looked multiselect , selectionmode in property panel, can't find it.
so how enable selecting rows in gridview?
thanks.
code behind
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) { } }
gridview 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" > <rowstyle cssclass="gridrow" width="800px" /> <selectedrowstyle backcolor="#ff0066" forecolor="white" /> </asp:gridview>
i think multiselect , selectionmode properties available vb.net grid, not in asp.net. bear in mind controls in asp.net html-in-disguise, may more limited. there no reason why can't have multi-select table, have plumbing yourself. need enable row selection, either handling rowdatabound event in
http://forums.asp.net/t/992062.aspx?how+to+select+row+in+gridview+on+click
or else using ms-provided option in
http://msdn.microsoft.com/en-us/library/wbk82279(v=vs.100).aspx
then need handle selectedindexchanging event, figure out row user clicked on, , handle row-colouring yourself.
Comments
Post a Comment