簡體   English   中英

GridView設置ComboBox值客戶端

[英]GridView Set ComboBox value Client side

我有一個帶有以下各列的GridView。

  1. 父級ID-綁定列
  2. 子ID-綁定列
  3. Desc-綁定列
  4. 狀態為ComboBox,值為YES,NO

家長ID有孩子ID。 如果我選擇“父母ID”組合框為“是”,則所有子值應填充為“是”。

我想使用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;
    }

找不到適合您的問題的解決方案。

請看看這個鏈接 我希望這將有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM