设置组合框值客户端

GridView Set ComboBox value Client side

本文关键字:客户端 组合 设置      更新时间:2023-09-26

我有一个GridView,包含以下列。

  1. 父ID -绑定列
  2. 子ID -绑定列
  3. 指定绑定列
  4. 状态为值为YES, NO的组合框

Parent ID有Child ID。如果我选择父ID组合框为YES,那么所有子值都应该填充为YES。

我想在客户端使用Java脚本。你能给我指路吗?

              <asp:datagrid id="dgImpact" runat="server" Width="78%" CellSpacing="0" AlternatingItemStyle-Height="20px"
                            AutoGenerateColumns="False" BorderColor="#3A6EA5" ItemStyle-ForeColor="blue" 
        CellPadding="0" BorderWidth="0px">
                            <AlternatingItemStyle Height="20px" BackColor="#EEF5FB"></AlternatingItemStyle>
                            <ItemStyle Height="20px" ForeColor="DarkBlue" BackColor="#DCEDF9"></ItemStyle>
                            <HeaderStyle Font-Names="Estrangelo Edessa" Font-Bold="True" Wrap="False" ForeColor="White" BorderColor="#336491"
                                BackColor="#336491"></HeaderStyle>
                            <Columns>
                                <asp:ButtonColumn>
                                    <ItemStyle Width="20px"></ItemStyle>
                                </asp:ButtonColumn>
                                <asp:ButtonColumn>
                                    <ItemStyle Width="20px"></ItemStyle>
                                </asp:ButtonColumn>
                                <asp:ButtonColumn>
                                    <ItemStyle Width="20px"></ItemStyle>
                                </asp:ButtonColumn>
                                <asp:BoundColumn Visible="False" DataField="QuestionID" ReadOnly="True">
                                    <HeaderStyle HorizontalAlign="Left"></HeaderStyle>
                                    <ItemStyle Wrap="False" HorizontalAlign="Left"></ItemStyle>
                                </asp:BoundColumn>
                                <asp:TemplateColumn HeaderText="Questions">
                                    <HeaderStyle HorizontalAlign="Left"></HeaderStyle>
                                    <ItemStyle Width="320px"></ItemStyle>
                                    <ItemTemplate>
                                        <asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.QuestionDesc") %>' ID="Label1">
                                        </asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateColumn>
                                <asp:TemplateColumn HeaderText="Status">
                                    <HeaderStyle HorizontalAlign="Center"></HeaderStyle>
                                    <ItemStyle Wrap="False" HorizontalAlign="Center"></ItemStyle>
                                    <ItemTemplate>
                                        <asp:dropdownlist CssClass="ComboStyle" Visible="True" Runat="server" ID="cmbAnswers" Width="72px" SelectedValue='<%# Bind("Status") %>'
                                        DataSource='<%# (new string[] { "--Select--","Yes", "No", "NA","Unknown" }) %>'></asp:dropdownlist>
                                    </ItemTemplate>
                                </asp:TemplateColumn>
                            </Columns>
                        </asp:datagrid>

cs

           protected void Page_Load(object sender, EventArgs e)
    {
        DataSet dstQuesData = getRiskDisciplineQuestionAnswer();
        dgImpact.DataSource = dstQuesData;
        dgImpact.DataBind();
        DataTable dtFinalTable = dstQuesData.Tables[0];
        for (int intRowCount = 0; intRowCount <= dgImpact.Items.Count - 1; intRowCount++)
        {
                long a = Convert.ToInt64(dtFinalTable.Rows[intRowCount][9]);
            ///    'If the Question Display is root
            if (a.ToString().Length == 3)
            {
                ((DataGridItem)dgImpact.Items[intRowCount]).Cells[4].ColumnSpan = 4;
                dgImpact.Items[intRowCount].Cells[0].Visible = false;
                dgImpact.Items[intRowCount].Cells[1].Visible = false;
                dgImpact.Items[intRowCount].Cells[2].Visible = false;
                //If the Question Displayed is at Level 1
            }
            else if (a.ToString().Length == 6 )
            {
                ((DataGridItem)dgImpact.Items[intRowCount]).Cells[4].ColumnSpan = 3;
                dgImpact.Items[intRowCount].Cells[0].Visible = true ;
                dgImpact.Items[intRowCount].Cells[1].Visible = false;
                dgImpact.Items[intRowCount].Cells[2].Visible = false;
                //If the Question Displayed is at Level 2
            }
            else if (a.ToString().Length == 9)
            {
                ((DataGridItem)dgImpact.Items[intRowCount]).Cells[4].ColumnSpan = 2;
                dgImpact.Items[intRowCount].Cells[0].Visible = true;
                dgImpact.Items[intRowCount].Cells[1].Visible = true;
                dgImpact.Items[intRowCount].Cells[2].Visible = false;
            }
            else if (a.ToString().Length == 12)
            {
                ((DataGridItem)dgImpact.Items[intRowCount]).Cells[4].ColumnSpan = 1;
                dgImpact.Items[intRowCount].Cells[0].Visible = true;
                dgImpact.Items[intRowCount].Cells[1].Visible = true;
                dgImpact.Items[intRowCount].Cells[2].Visible = true;
            }
        }
    }
    public DataSet getRiskDisciplineQuestionAnswer()
    {
        DataSet riskQuestionAnswerData = new DataSet();
        sqlConnection = new SqlConnection(connStr);
        sqlCommand = new SqlCommand("usp_testRDD1", sqlConnection);
        sqlCommand.CommandType = CommandType.StoredProcedure;
        sqlDataAdapter = new SqlDataAdapter(sqlCommand);
        try
        {
            sqlDataAdapter.Fill(riskQuestionAnswerData);
        }
        catch
        {
            throw;
        }
        return riskQuestionAnswerData;
    }

找不到合适的解决方案。

请看看这个链接。我希望这对你有帮助。