1

我有一个问题,我想在下拉列表中的值被提取后,插入到数据库中我希望它隐藏下拉列表并只显示用户评分的产品等级,如下两个图片:

这是第一张显示用户需要如何将等级插入产品数据库的图片:

在此处输入图像描述

之后的结果应该如下:

在此处输入图像描述

对产品进行评分的用户现在应该看不到下拉列表。我尝试使用 RowDataBound 事件和以下代码:

  if (e.Row.RowType == DataControlRowType.DataRow)
            {
        hsp_Narudzbe_Detalji_Result k = (hsp_Narudzbe_Detalji_Result)e.Row.DataItem;
                if (k.Ocjena!=null)
                {
                    e.Row.Cells[4].Text = k.ocjena;
                }
            }

但它不起作用,它只显示一次等级,当我按下产品分级按钮时,下拉列表又回来了......:/

有人可以帮我解决这个问题吗?

编辑(页面的aspx代码):

<asp:GridView ID="gridDetaljiNarudzbe" AutoGenerateColumns="false" AllowPaging="true" PageSize="10" runat="server" OnRowCommand="gridDetaljiNarudzbe_RowCommand" OnPageIndexChanging="gridDetaljiNarudzbe_PageIndexChanging" OnRowDataBound="gridDetaljiNarudzbe_RowDataBound">
        <Columns>
           <asp:BoundField DataField="Naziv" HeaderText="Naziv" />
           <asp:BoundField DataField="Sifra" HeaderText="Šifra" />
           <asp:BoundField DataField="Cijena" HeaderText="Cijena" />
           <asp:BoundField DataField="Kolicina" HeaderText="Količina" />
                <asp:TemplateField HeaderText="Ocjena">
                <ItemTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList>
                </ItemTemplate>
            </asp:TemplateField>
          <asp:TemplateField>
              <ItemTemplate> 
                   <asp:LinkButton ID="btnOcijeni" title="Ocijeni proizvod" CommandName="OcijeniCommand" CommandArgument='<%#Eval("ProizvodID") + ";" +((GridViewRow) Container).RowIndex%>' runat="server"><img src="../images/ocijeni.png" /></asp:LinkButton>
              </ItemTemplate>
          </asp:TemplateField>
        </Columns>
    </asp:GridView>

成绩是这样加载的:

 if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DropDownList drop = e.Row.FindControl("DropDownList1") as DropDownList;
                drop.Items.Add(new ListItem(""));
                drop.Items.Add(new ListItem("1"));
                drop.Items.Add(new ListItem("2"));
                drop.Items.Add(new ListItem("3"));
                drop.Items.Add(new ListItem("4"));
                drop.Items.Add(new ListItem("5"));
            }
4

2 回答 2

2

试试这样的,

     protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        DropDownList ddl = e.Row.Cells[4].FindControl("DropDownList2") as DropDownList;
        if (ddl != null)
        {
            // if (your_condition == true)
            //{
                    ddl .Visible = false;

            //}

        }
    }
}
于 2014-11-19T12:57:53.743 回答
2

嗨,让您的项目模板如下所示:

<ItemTemplate>
                <asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList>
                 <asp:Label ID="gvlblddlVal" runat="server" Text='<%#((YourEntityClassName)Container.DataItem).ddlVal %>'></asp:Label>
            </ItemTemplate>

在那之后

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
    DropDownList ddl = e.Row.Cells[4].FindControl("DropDownList2") as DropDownList;
    Label lblddl = e.Row.Cells[4].FindControl("gvlblddlVal") as Label;
    if (!string.IsNullOrEmpty(lblddl.Text))
    {            
                ddl.Visible = false;
                lblddl.Visible = true;           
    }
    else
    {
                ddl.Visible = true;
                lblddl.Visible =false; 
     }
  }
}

希望能帮助到你

于 2014-11-19T13:05:07.650 回答