网格视图中的下拉列表在选择后返回默认值

发布于 2024-12-05 05:47:02 字数 17526 浏览 2 评论 0原文

我在网格视图中有一个下拉列表,还有一个链接按钮、按钮和面板。如下图所示。当我在下拉列表中选择一个值时,它会返回默认值

我尝试将 gridview 放入 updatepanel 并将 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 

谢谢


@Tim 谢谢你,这真的很有帮助,我按照你所说的代码做了下面的事情。但我需要一些数据绑定到同一个 gridview 中的标签上,即 yi 有 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

I have a dropdownlist in a gridview, also have a a linkbutton, button and panel. as shown below. when i select a value in dropdown list it returns to default

I have tried to put the gridview in an updatepanel and set the enable viewstate of the dropdrownlist to true and that did help, please any one with suggestions.

<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>
             </td>
        <td>
             </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>
             </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>
             </td>
        <td>
             </td>
    </tr>

</table>
</asp:Panel>

The code behind

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 

Thank you


@Tim Thank you, this was really helpful i did what you said code below. but i need some data to bind on a label in the same gridview that is y i have SelectedIndexChanged event-handler. I am still having a little challenge i want to be able to bind data on labels in d row which d dropdownlist where a value was selected but what i have seem to bind to the label on the first row only, regardless of the dropdownlist that was selected. Any pointers??

<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>
         </td>
    <td>
         </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>
         </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>
         </td>
    <td>
         </td>
</tr>

code behind

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

听不够的曲调 2024-12-12 05:47:02

不要使用 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类代码在Gridview的edit_event后面..

DropDownList ddlClassName = (DropDownList) (DetailsGrid.Rows[index2].Cells[0].FindControl("ddlClass"));

字符串 ClassNamevalue = ddlClassName.SelectedValue.Trim();

Do not use Dropdown1_selected Index changed...

User as following in aspx file....``

 <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 Class code behind in edit_event of Gridview..

DropDownList ddlClassName = (DropDownList) (DetailsGrid.Rows[index2].Cells[0].FindControl("ddlClass"));

string ClassNamevalue = ddlClassName.SelectedValue.Trim();

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文