выпадающий список в виде сетки возвращается к значению по умолчанию после выбора - PullRequest
1 голос
/ 19 сентября 2011

У меня есть выпадающий список в виде сетки, также есть кнопка ссылки, кнопка и панель. как показано ниже. когда я выбираю значение в раскрывающемся списке, он возвращается к значению по умолчанию

Я попытался поместить gridview в панель обновления и установить для состояния просмотра dropdrownlist значение true, и это помогло, пожалуйста, у любого с предложениями.

<table align="center" cellpadding="0" cellspacing="0" class="box" 



        <tr>
            <td colspan="4" class="pText" align="center">
                <b>Treatment Details<br />
                </b>
                <asp:LinkButton ID="LinkButton6" runat="server" CssClass="grey1">Basic Billing</asp:LinkButton>
</td>
</tr>
</table>

   <asp:Panel ID="Panel4" runat="server" Visible="False">
<table align="center" cellpadding="0" cellspacing="0" 
        style="height: 88px; width: 294px">
    <tr>
        <td align="right" class="grey1" colspan="2" style="height: 13px">
            .:Basic Billing</td>
    </tr>
    <tr>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
    </tr>
 <tr>
        <td class="pText" style="height: 19px">
            Enter policy Number:</td>
        <td style="height: 19px">
            <asp:TextBox ID="TextBox1" runat="server" CssClass="textfields">       </asp:TextBox>

           </td>
    </tr>
    <tr>
        <td class="pText" style="height: 19px">
            Enter Number of Basic Billing Item:</td>
        <td style="height: 19px">
            <asp:TextBox ID="TextBox2" runat="server" CssClass="textfields"></asp:TextBox>

        </td>
    </tr>

    <tr>
        <td>
            &nbsp;</td>
        <td>
            <asp:Button ID="Button1" runat="server" CssClass="textfields" Text="Submit" />
        </td>
    </tr>
    <tr>
        <td colspan="2">
        <asp:UpdatePanel ID="UpdatePanel3" runat="server">
        <ContentTemplate>

        <asp:GridView ID="GridView2" runat="server"
                AllowSorting="True" AlternatingRowStyle-CssClass="alt" 
                AutoGenerateColumns="False" CellPadding="2" CssClass="MyGridView" 
                OnRowCommand="GridView1_RowCommand" OnRowCreated="GridView1_RowCreated" 
                OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing" 
                PagerStyle-CssClass="pgr" Width="750px">
                <Columns>
                    <asp:TemplateField HeaderText="S/N">
                        <ItemTemplate>
                            <%# Container.DataItemIndex + 1 %>
                        </ItemTemplate>
                        <HeaderStyle HorizontalAlign="Center" />
                        <ItemStyle HorizontalAlign="Center" />
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="Item">
                        <ItemStyle HorizontalAlign="Left" />
                        <HeaderStyle HorizontalAlign="Left" />
                        <ItemTemplate>
                            <asp:DropDownList ID="drpOutp" runat="server" CssClass="textfields" OnSelectedIndexChanged="drpOutp_SelectedIndexChanged" AutoPostBack="true" OnLoad="Load_OutpDetail">
                            </asp:DropDownList>
                            <controlstyle bordercolor="LightGray" />
                        </ItemTemplate>
                    </asp:TemplateField>

                     <asp:TemplateField HeaderText="Unit Price">
                        <ItemStyle HorizontalAlign="Left" />
                        <HeaderStyle HorizontalAlign="Left" />
                        <ItemTemplate>
                            <asp:Label ID="lblUnit" runat="server"></asp:Label>
                            <controlstyle bordercolor="LightGray" />
                        </ItemTemplate>
                        </asp:TemplateField>

                    <asp:TemplateField HeaderText="Quantity">
                        <ItemStyle HorizontalAlign="Left" />
                        <HeaderStyle HorizontalAlign="Left" />
                        <ItemTemplate>
                            <asp:TextBox ID="txteffdate" runat="server" CssClass="textfields" Height="15px" Width="80px"></asp:TextBox>
                            <controlstyle bordercolor="LightGray" />
                        </ItemTemplate>
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="Total Price">
                        <ItemStyle HorizontalAlign="Left" />
                        <HeaderStyle HorizontalAlign="Left" />
                        <ItemTemplate>
                            <asp:Label ID="lblTotalP" runat="server"></asp:Label>
                            <controlstyle bordercolor="LightGray" />
                        </ItemTemplate>
                    </asp:TemplateField>

                </Columns>
                <HeaderStyle CssClass="tblPageHeaderII_new" />
                <AlternatingRowStyle BackColor="#F4F4F4" />
                <PagerStyle HorizontalAlign="Right" />
                <EmptyDataTemplate>
                    <asp:Label ID="Label2" runat="server" Text="No Data Returned !"></asp:Label>
                </EmptyDataTemplate>
            </asp:GridView>

        </ContentTemplate>
        </asp:UpdatePanel>

        </td>
    </tr>
    <tr>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
    </tr>

</table>
</asp:Panel>

Код позади

Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
    Panel3.Visible = True
End Sub

Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
    Try
        Dim params() As SqlParameter = {New SqlParameter("@PolicyNumber", Trim(txtPolicy.Text)), _
                                    New SqlParameter("@IPAddress", Request.ServerVariables("REMOTE_ADDR")), _
                                   New SqlParameter("@PostedBy", Session("HMOUser"))}

        Dim retValue As Data.DataRow = SqlHelper.ExecuteDataset(Connstring, CommandType.StoredProcedure, "HMO_Enrollee_CheckByPolicyNumber", params).Tables(0).Rows(0)

        If retValue Is Nothing Then

            lblmsg.Text = "Invalid Policy Number"
            txtPolicy.Text = ""

        Else
            Session("Enr") = retValue.Table.Rows(0).Item("Enrollee_Number")

Catch ex As Exception
                HMO_BLL.WriteLog(ex.Message + ex.StackTrace)
            End Try


        End If

    Catch ex As Exception

        lblmsg.Text = "Invalid Policy Number"
    End Try

Dim nos As Integer() = New Integer(Convert.ToInt32(txtItemNo.Text) - 1) {}
    For i As Integer = 0 To nos.Length - 1
        nos(i) = i + 1
    Next
    GridView1.DataSource = nos
    GridView1.DataBind()

End Sub

Public Sub Load_OutpDetail(ByVal sender As Object, ByVal e As EventArgs)
    'If Not IsPostBack Then


    Try
        Dim ds As Data.DataSet = DAL.HMO_Outp_Detail_drpdown()
        Dim Li As ListItem
        Li = New ListItem
        Li.Value = "0"
        Li.Text = "-- Select --"

        Dim drpOutp As DropDownList = DirectCast(sender, DropDownList)

        drpOutp.AppendDataBoundItems = True
        drpOutp.Items.Clear()
        drpOutp.Items.Add(Li)

        If Not ds Is Nothing And ds.Tables(0).Rows.Count > 0 Then
            With drpOutp
                .DataSource = ds.Tables(0)
                .DataTextField = "OutpDetail"
                .DataValueField = "OutpID"
                .DataBind()
                .SelectedIndex = 0
            End With
        Else
            drpOutp.Enabled = False

        End If
        ds.Dispose()

    Catch ex As Exception
        HMO_BLL.WriteLog(ex.Message + ex.StackTrace)
    End Try
    'End If
End Sub
Protected Sub drpOutp_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
    Try
        For Each gvRow As GridViewRow In GridView1.Rows

            Dim drpOutp As DropDownList = DirectCast(gvRow.FindControl("drpOutp"), DropDownList)
            Dim lblEffDate As Label = DirectCast(gvRow.FindControl("lblEffDate"), Label)

            'Dim drpOutp As DropDownList = DirectCast(sender, DropDownList)

            Dim params() As SqlParameter = {New SqlParameter("@OutpID", drpOutp.SelectedValue), _
                                            New SqlParameter("@ProviderID", HiddenField1.Value)}
            Dim retValue As Data.DataRow = SqlHelper.ExecuteDataset(Connstring, CommandType.StoredProcedure, "HMO_Outp_Fetch_price", params).Tables(0).Rows(0)
            lblEffDate.Text = retValue.Table.Rows(0).Item("Uprice")
        Next

    Catch ex As Exception
        HMO_BLL.WriteLog(ex.Message + ex.StackTrace)
    End Try
End Sub 

Спасибо


@ Тим Спасибо, это было действительно полезно, я сделал то, что вы сказали, код ниже. но мне нужны некоторые данные для привязки к метке в том же виде сетки, что и у меня есть обработчик событий SelectedIndexChanged. У меня все еще есть небольшая проблема, я хочу иметь возможность привязывать данные к меткам в строке d, которые d выпадающий список, где было выбрано значение, но то, что я, кажется, привязал к метке только в первой строке, независимо от выпадающего списка, который был выбран. Любые указатели ??

<table align="center" cellpadding="0" cellspacing="0" class="box" 



    <tr>
        <td colspan="4" class="pText" align="center">
            <b>Treatment Details<br />
            </b>
            <asp:LinkButton ID="LinkButton6" runat="server" CssClass="grey1">Basic Billing</asp:LinkButton>
   </td>
    </tr>
   </table>

       <asp:Panel ID="Panel4" runat="server" Visible="False">
<table align="center" cellpadding="0" cellspacing="0" 
    style="height: 88px; width: 294px">
<tr>
    <td align="right" class="grey1" colspan="2" style="height: 13px">
        .:Basic Billing</td>
</tr>
<tr>
    <td>
        &nbsp;</td>
    <td>
        &nbsp;</td>
</tr>
 <tr>
           <td class="pText" style="height: 19px">
            Enter policy Number:</td>
    <td style="height: 19px">
        <asp:TextBox ID="TextBox1" runat="server" CssClass="textfields">       </asp:TextBox>

       </td>
</tr>
<tr>
    <td class="pText" style="height: 19px">
        Enter Number of Basic Billing Item:</td>
    <td style="height: 19px">
        <asp:TextBox ID="TextBox2" runat="server" CssClass="textfields"></asp:TextBox>

    </td>
</tr>

<tr>
    <td>
        &nbsp;</td>
    <td>
        <asp:Button ID="Button1" runat="server" CssClass="textfields" Text="Submit" />
    </td>
</tr>
<tr>
    <td colspan="2">
    <asp:UpdatePanel ID="UpdatePanel3" runat="server">
    <ContentTemplate>

    <asp:GridView ID="GridView2" runat="server"
            AllowSorting="True" AlternatingRowStyle-CssClass="alt" 
            AutoGenerateColumns="False" CellPadding="2" CssClass="MyGridView" 
            OnRowCommand="GridView1_RowCommand" OnRowCreated="GridView1_RowCreated" 
            OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing" 
            PagerStyle-CssClass="pgr" Width="750px">
            <Columns>
                <asp:TemplateField HeaderText="S/N">
                    <ItemTemplate>
                        <%# Container.DataItemIndex + 1 %>
                    </ItemTemplate>
                    <HeaderStyle HorizontalAlign="Center" />
                    <ItemStyle HorizontalAlign="Center" />
                </asp:TemplateField>

                <asp:TemplateField HeaderText="Item">
                    <ItemStyle HorizontalAlign="Left" />
                    <HeaderStyle HorizontalAlign="Left" />
                    <ItemTemplate>
                        <asp:DropDownList ID="drpOutp" runat="server" CssClass="textfields" OnSelectedIndexChanged="drpOutp_SelectedIndexChanged" AutoPostBack="true" OnLoad="Load_OutpDetail">
                        </asp:DropDownList>
                        <controlstyle bordercolor="LightGray" />
                    </ItemTemplate>
                </asp:TemplateField>

                 <asp:TemplateField HeaderText="Unit Price">
                    <ItemStyle HorizontalAlign="Left" />
                    <HeaderStyle HorizontalAlign="Left" />
                    <ItemTemplate>
                        <asp:Label ID="lblUnit" runat="server"></asp:Label>
                        <controlstyle bordercolor="LightGray" />
                    </ItemTemplate>
                    </asp:TemplateField>

                <asp:TemplateField HeaderText="Quantity">
                    <ItemStyle HorizontalAlign="Left" />
                    <HeaderStyle HorizontalAlign="Left" />
                    <ItemTemplate>
                        <asp:TextBox ID="txteffdate" runat="server" CssClass="textfields" Height="15px" Width="80px"></asp:TextBox>
                        <controlstyle bordercolor="LightGray" />
                    </ItemTemplate>
                </asp:TemplateField>

                <asp:TemplateField HeaderText="Total Price">
                    <ItemStyle HorizontalAlign="Left" />
                    <HeaderStyle HorizontalAlign="Left" />
                    <ItemTemplate>
                        <asp:Label ID="lblTotalP" runat="server"></asp:Label>
                        <controlstyle bordercolor="LightGray" />
                    </ItemTemplate>
                </asp:TemplateField>

            </Columns>
            <HeaderStyle CssClass="tblPageHeaderII_new" />
            <AlternatingRowStyle BackColor="#F4F4F4" />
            <PagerStyle HorizontalAlign="Right" />
            <EmptyDataTemplate>
                <asp:Label ID="Label2" runat="server" Text="No Data Returned !"></asp:Label>
            </EmptyDataTemplate>
        </asp:GridView>

    </ContentTemplate>
    </asp:UpdatePanel>

    </td>
</tr>
<tr>
    <td>
        &nbsp;</td>
    <td>
        &nbsp;</td>
</tr>

код позади

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
    Try
        If e.Row.RowType = DataControlRowType.DataRow Then


            Dim ctrl As Control = e.Row.FindControl("drpOutp")


            If ctrl IsNot Nothing Then
                Dim ddl As DropDownList = TryCast(ctrl, DropDownList)


                Dim ds As Data.DataSet = DAL.HMO_Outp_Detail_drpdown()
                Dim Li As ListItem
                Li = New ListItem
                Li.Value = "0"
                Li.Text = "-- Select --"



                ddl.AppendDataBoundItems = True
                ddl.Items.Clear()
                ddl.Items.Add(Li)

                If Not ds Is Nothing And ds.Tables(0).Rows.Count > 0 Then
                    With ddl
                        .DataSource = ds.Tables(0)
                        .DataTextField = "OutpDetail"
                        .DataValueField = "OutpID"
                        .DataBind()
                        .SelectedIndex = 0
                    End With
                Else
                    ddl.Enabled = False

                End If
                ds.Dispose()
            End If
        End If

    Catch ex As Exception
        HMO_BLL.WriteLog(ex.Message + ex.StackTrace)
    End Try

End Sub
Protected Sub drpOutp_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
    Try
        Dim ddl As DropDownList = TryCast(sender, DropDownList)

        For Each gvRow As GridViewRow In GridView1.Rows

            Dim ctrl As Control = TryCast(gvRow.FindControl("drpOutp"), DropDownList)
            If ctrl IsNot Nothing Then

                Dim ddl1 As DropDownList = DirectCast(ctrl, DropDownList)


                Dim params() As SqlParameter = {New SqlParameter("@OutpID", ddl.SelectedValue), _
                                                New SqlParameter("@ProviderID", HiddenField1.Value)}
                Dim retValue As Data.DataRow = SqlHelper.ExecuteDataset(Connstring, CommandType.StoredProcedure, "HMO_Outp_Fetch_price", params).Tables(0).Rows(0)
                Dim UnitP As Label = TryCast(gvRow.FindControl("lblUnit"), Label)
                UnitP.Text = retValue.Table.Rows(0).Item("Uprice")
                Exit For
            End If
        Next


    Catch ex As Exception
        HMO_BLL.WriteLog(ex.Message + ex.StackTrace)
    End Try
End Sub

    Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
    Dim nos As Integer() = New Integer(Convert.ToInt32(txtItemNo.Text) - 1) {}
    For i As Integer = 0 To nos.Length - 1
        nos(i) = i + 1
    Next
    GridView1.DataSource = nos
    GridView1.DataBind()

End Sub

1 Ответ

0 голосов
/ 11 января 2012

Не использовать Dropdown1_selected Индекс изменен ...

Пользователь, как указано в файле aspx .... ``

 <asp:DropDownList ID="ddlClass" runat="server" SelectedValue='<%#Eval("ClassName") %>'>
                            <asp:ListItem></asp:ListItem>
                            <asp:ListItem>9</asp:ListItem>
                            <asp:ListItem>10</asp:ListItem>
                            <asp:ListItem>11</asp:ListItem>
                            <asp:ListItem>12</asp:ListItem>
                            </asp:DropDownList>
                       </EditItemTemplate>   
                    </asp:TemplateField>

Код класса CS позади в вedit_event of Gridview.

DropDownList.trim ();

...