<asp:TemplateField HeaderText="job" Visible="true" > <ItemTemplate> <asp:DropDownList ID="dropjobqs" runat="server" Enabled="true" AutoPostBack="true" OnSelectedIndexChanged="dropjobq_CheckedChanged"> </asp:DropDownList> </ItemTemplate> </asp:TemplateField>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Response.Cache.SetCacheability(HttpCacheability.NoCache) setMenu() Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache) Response.Cache.SetNoStore() If Not Page.IsPostBack Then strtDate_CalendarExtender.TargetControlID = "strtDate" strtDate.CssClass = "~/css/calendar.css" strtDate_CalendarExtender.StartDate = DateTime.Now.ToShortDateString strtDate_CalendarExtender.EndDate = DateTime.Now.AddDays(1) ' Place1.Controls.Add(myCalExt) lbldte.Text = DateAndTime.Now.ToShortDateString SetInitialRow() End If End Sub Protected Sub OnRowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) If (e.Row.RowType = DataControlRowType.DataRow) Then 'Find the DropDownList in the Row Try Dim dropjobqs As DropDownList = CType(e.Row.FindControl("dropjobqs"), DropDownList) dropjobqs.DataSource = GetData("Select JBNME,JBCDE from JOBBSDB") dropjobqs.DataTextField = "JBNME" dropjobqs.DataValueField = "JBCDE" dropjobqs.DataBind() 'Add Default Item in the DropDownList dropjobqs.Items.Insert(0, New ListItem("Please select")) Catch ex As NullReferenceException Response.Write("Processor Usage" + ex.Message) 'the error in start generated here End Try End If ' dr.Dispose() End Sub Protected Sub dropjobq_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs) Dim row As GridViewRow = DirectCast(DirectCast(sender, DropDownList).NamingContainer, GridViewRow) Dim index As Integer = row.RowIndex Dim dt As DataTable = DirectCast(ViewState("CurrentTable"), DataTable) Dim rowIndex As Integer = 0 If dt.Rows.Count > 0 Then For i As Integer = 0 To dt.Rows.Count - 1 Dim dropjobqs As DropDownList = DirectCast(Gridview1.Rows(index).FindControl("dropjobqs"), DropDownList) If dropjobqs.SelectedIndex Then ViewState(dropjobqs.UniqueID) = dropjobqs.SelectedIndex Else ViewState.Remove(dropjobqs.UniqueID) End If ' If dropjobqs.SelectedIndex Then 'ViewState(dropjobqs.UniqueID) = dropjobqs.SelectedIndex ' Else 'ViewState.Remove(dropjobqs.UniqueID) ' End If rowIndex += 1 dropjobqs.DataSource = dr dropjobqs.DataBind() Next End If End Sub Private Function GetData(ByVal query As String) As DataSet If Not IsPostBack Then da = clnconn.MyDataAdapterclnc("Select JBNME,JBCDE from JOBBSDB") da.Fill(ds) End If Return ds End Function
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)