Как отобразить выбранное значение строки / текст внутри выпадающего - PullRequest
0 голосов
/ 09 октября 2019

Итак, я новичок в использовании ASP.net, и мне трудно отобразить значение / текст выбранной строки в раскрывающемся списке. Я просто хочу выбрать строку в гривью, и когда я выбираю, значения в ней должны заполнять текстовые поля и выпадающий список, кто-то может мне помочь? спасибо

это мой код, как вы можете видеть в части LoadData () я использовал .findtext (), но он выдает ошибку: ссылка на объект не установлена ​​на экземпляр объекта.

protected void grdRecentCases_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
   {
       if (e.Row.RowType == DataControlRowType.DataRow)
       {
           e.Row.Attributes["onmouseover"] = "this.style.cursor='hand';this.style.textDecoration='underline';this.style.cursor='Pointer'";
           e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';";
           e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.grdRecentCases, "Select$" + e.Row.RowIndex);
       }
   }


   protected void grdRecentCases_RowCommand(Object sender, GridViewCommandEventArgs e)
   {
       if (e.CommandName == "Select")
       {
           LoadData(Convert.ToInt32(e.CommandArgument));

       }
   }

   ///<summary> LoadData is used to populate inputboxes with the value of the selected griview row</summary>
   ///<param name="rowNumber"> Indicates whether there is a selected row or non</param>
   private void LoadData(int? rowNumber = null)
   {
       //if rowNumber is null use GridView1.SelectedIndex
       var index = rowNumber ?? grdRecentCases.SelectedIndex;

       //Populate the input box with the value of selected row.
       GridViewRow gr = grdRecentCases.Rows[index];
       txtDepartmentCase.Text = gr.Cells[2].Text;
       txtLabCase.Text = gr.Cells[5].Text;
       txtIncidentReportDate.Text = gr.Cells[6].Text;
       txtCaseKey.Text = gr.Cells[1].Text;
       drpDepartment.Items.FindByText(gr.Cells[3].Text).Selected = true;
       drpCharge.Items.FindByText(gr.Cells[4].Text).Selected = true;

   }

HTML-код

<table class="style2">
            <tr>
                <td class="style3">
                    Department Case #
                </td>
                <td>
                    <asp:TextBox ID="txtDepartmentCase" runat="server" Enabled="False"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="style3">
                    Department
                </td>
                <td>
                    <asp:DropDownList ID="drpDepartment" runat="server" Height="18px" Width="153px" Enabled="False"
                        AppendDataBoundItems="true" AutoPostBack="true" OnSelectedIndexChanged="drpDepartment_SelectedIndexChanged"
                        Visible="true">
                    </asp:DropDownList>
                    <asp:TextBox ID="txtDepartment" runat="server" Enabled="False"></asp:TextBox>


                </td>
            </tr>
            <tr>
                <td class="style3">
                    Charge
                </td>
                <td>
                    <asp:DropDownList ID="drpCharge" runat="server" Height="22px" Width="153px" Enabled="False"
                        AppendDataBoundItems="true" AutoPostBack="true"  OnSelectedIndexChanged="drpCharge_SelectedIndexChanged"
                        Visible="true">
                    </asp:DropDownList>
                    <asp:TextBox ID="txtCharge" runat="server" Enabled="False"></asp:TextBox>


                </td>
            </tr>
            <tr>
                <td class="style3">
                    Lab Case #
                </td>
                <td>
                    <asp:TextBox ID="txtLabCase" runat="server" Enabled="False"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="style3">
                    Incident Report Date
                </td>
                <td>
                    <asp:TextBox ID="txtIncidentReportDate" runat="server" Enabled="False"></asp:TextBox>
                </td>
            </tr>
        </table>

1 Ответ

0 голосов
/ 09 октября 2019

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

Надеюсь, это поможет вам. Создайте событие просмотра данных, RowHeaderMouseClick

     private void datagridview_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
    {
        string selectedDoc = datagridview.Rows[datagridview.SelectedRows[0].Index].Cells["column name"].Value.ToString() ;

        combobox.Text = selectedDoc;
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...