faraz ali

faraz ali

  • NA
  • 5
  • 2.2k

Gridview Combobox selected index change event problem

May 3 2013 2:34 AM
I want to Open file from gridview combobox selected index change event depending on combobox value which will fill from database in databound event . all work done but when i use responce.redirect(combobox.selecteditem.text) it open file but every time it collect only row 0 index . My Problem is that when ever i change any other combobox selected index it first check from top of grid if any combobox.selectedindex>0 it will open that file not my selected file from combobox.

<asp:TemplateField HeaderText="Attachment">
<ItemTemplate >

<asp:DropDownList ID="DropDownList1" EnableViewState="true" AutoPostBack="true" runat="server" Width="100px" OnSelectedIndexChanged="iconUsers_SelectedIndexChanged">

</asp:DropDownList>


</ItemTemplate>

<HeaderStyle Wrap="False" Width="100px" />
<ItemStyle Wrap="False" HorizontalAlign="Left" Width="100px" />

</asp:TemplateField>


Protected Sub GridView1_DataBound(ByVal sender As Object, ByVal e As EventArgs) Handles GridView1.DataBound
GridView1.Columns(1).Visible = False

  For Each row In GridView1.Rows
   Dim taskno As Label = CType(row.FindControl("lbltaskno"), Label)
Dim mydropdown As DropDownList = CType(row.FindControl("DropDownList1"), DropDownList)
QRY = "select Attachment.AttachTask from Attachment join TaskAssignment on Attachmentno=TaskUniqueNo where Attachmentno='" & taskno.Text & "'"
mydropdown.Items.Clear()
mydropdown.Items.Add(New ListItem("Select One", 0))
Dim i As Integer
dtTaskAssig = objtms.GetAdapter(QRY)
For i = 0 To dtTaskAssig.Rows.Count - 1
mydropdown.Items.Add(New ListItem(dtTaskAssig.Rows(i)(0).ToString))
Next
If mydropdown.Items.Count < 2 Then
mydropdown.Visible = False
End If
    Next

End Sub


Protected Sub iconUsers_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Dim ddl As DropDownList = DirectCast(sender, DropDownList)
Dim row As GridViewRow = DirectCast(ddl.NamingContainer, GridViewRow)
Dim idx As Integer = row.RowIndex
Dim ddlTaskList As DropDownList = DirectCast(row.Cells(0).FindControl("DropDownList1"), DropDownList)
If ddlTaskList.SelectedIndex > 0 Then
Dim a As String = ddlTaskList.SelectedItem.Text
Response.Redirect(a, True)
End If
End Sub