Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# gridview中模板字段中的下拉列表存在问题_C#_Asp.net_Gridview_Drop Down Menu_Disabled Control - Fatal编程技术网

C# gridview中模板字段中的下拉列表存在问题

C# gridview中模板字段中的下拉列表存在问题,c#,asp.net,gridview,drop-down-menu,disabled-control,C#,Asp.net,Gridview,Drop Down Menu,Disabled Control,好的,我有一个gridview,如下html所示: <asp:GridView ID="gridDetaljiNarudzbe" AutoGenerateColumns="false" AllowPaging="true" PageSize="10" runat="server" OnRowCommand="gridDetaljiNarudzbe_RowCommand" OnPageIndexChanging="gridDetaljiNarudzbe_PageIndexChanging"

好的,我有一个gridview,如下html所示:

 <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") %>' runat="server"><img src="../images/ocijeni.png" /></asp:LinkButton>
              </ItemTemplate>
          </asp:TemplateField>
        </Columns>
    </asp:GridView>
用于从每行的下拉列表中选择值:

   foreach (GridViewRow gr in gridDetaljiNarudzbe.Rows)
{
                        DropDownList drop = gr.FindControl("DropDownList1") as DropDownList;
                     // now selecting a value from dropdownlist 
                 int selectednumber = Convert.ToInt32(drop.Text);
}
现在我的问题是,假设网格中有两条记录,我想从第二行的第二个下拉列表中选择值(假设我这样做了)。当我按下第一行第一条记录的按钮时,我从第二个下拉列表中选择的值现在被插入到DB中,就好像我从第一个下拉列表中选择了什么一样

另外,我想知道是否有可能在下拉列表中提取某些内容并插入数据库后,现在禁用该下拉列表,并将其转换为静态文本,只显示5而不是下拉列表

有人能帮我解决这个问题吗?我什么都试过了,但还没有成功/

编辑:

当我从第二个网格(你可以看到图片的第二个下拉列表)中选择某个内容时,当我按下按钮给第一个产品评分时,我从我选择的第二个下拉列表中获得评分。现在清楚了吗

谢谢

以下是瑜珈的代码:

   List<hsp_Proizvodi_SprijeciDvaPutaOcijeniti_Result> lista = ServisnaKlasa.SprijeciDvostrukoOcjenjivanje(ProizvodID, Sesija.kupac.KupacID);
                foreach (GridViewRow gr in gridDetaljiNarudzbe.Rows)
                {
                    if (lista.Count == 0)
                    {
                        DropDownList drop = gr.FindControl("DropDownList1") as DropDownList;
                        if (drop.SelectedIndex != 0)
                        {
                            Ocjene o = new Ocjene();
                            o.KupacID = Sesija.kupac.KupacID;
                            o.ProizvodID = ProizvodID;
                            o.Datum = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
                            o.Ocjena = Convert.ToInt32(drop.Text);
                            ServisnaKlasa.OcjenjivanjeProizvoda(o);
                            string poruka = "Proizvod uspješno ocijenjen!";
                            ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + poruka + "');", true);
                            drop.SelectedIndex = 0;

                        }
                    }
                    else
                    {
                        string poruka = "Ovaj proizvod ste već ocijenili!";
                        ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + poruka + "');", true);
                    }
                }
List lista=ServisnaKlasa.sprijecidvostruokjenjivanje(ProizvodID,Sesija.kupac.KupacID);
foreach(gridDetaljiNarudzbe.Rows中的GridViewRow gr)
{
如果(lista.Count==0)
{
DropDownList drop=gr.FindControl(“DropDownList1”)作为DropDownList;
如果(drop.SelectedIndex!=0)
{
Ocjene o=新的Ocjene();
o、 KupacID=Sesija.kupac.KupacID;
o、 ProizvodID=ProizvodID;
o、 Datum=DateTime.Now.ToString(“dd/MM/yyyy HH:MM:ss”,System.Globalization.CultureInfo.InvariantCulture);
o、 Ocjena=Convert.ToInt32(drop.Text);
ServisnaKlasa.OcjenjivanjeProizvoda(o);
字符串poruka=“Proizvod uspješno ocijenjen!”;
RegisterStartupScript(this.GetType(),“myalert”,“alert(“+poruka+”);”,true);
drop.SelectedIndex=0;
}
}
其他的
{
字符串poruka=“Ovaj proizvod ste većocijenili!”;
RegisterStartupScript(this.GetType(),“myalert”,“alert(“+poruka+”);”,true);
}
}
遵循这种方法

  • 添加gridview的
    row命令
    事件
  • 为链接按钮提供一个命令参数。如下所示

    <asp:LinkButton ID="btnOcijeni" title="Ocijeni proizvod" CommandName="OcijeniCommand" CommandArgument='<%#Eval("ProizvodID") + ";" +((GridViewRow) Container).RowIndex%>' runat="server"><img src="../images/ocijeni.png" /></asp:LinkButton>
    

  • 现在,在同一个item命令事件中,在将值插入db之后添加以下代码

                        //Access the new label
                        Label lblfordrpdwn= (Label)gridDetaljiNarudzbe.Rows[index].FindControl("lbl_ForDrpdwnVal");
                        lblfordrpdwn.Text= drpdwn1.SelectedItem.Text;//Setting value from dropdown to lbel
                        lblfordrpdwn.Visible=true;//Showing label
                        drpdwn1.Visible=false;//Hiding the dropdown
    

  • 第一行下拉列表和第二行下拉列表的关系是什么。你不是很清楚。你想要什么?问题是什么?你能澄清一下吗?你能看到这张图片吗:当我从第二个网格中选择某个东西时(你可以看到图片的第二个下拉列表),当我按下按钮给第一个产品打分时,我从我选择的第二个下拉列表中得到分数。现在清楚了吗?对不起,我看不到这张照片。可以编辑你的问题吗?你只是在说正在发生的事情,而不是你想要的!你不想再从第二次扣分中得到分数了吗?不,不是这样,请看更新问题上的图片。P、 我希望它现在更清楚,伙计,你最好,它工作!!!你能再帮我一件事吗?现在,在DB中插入某些内容(针对某一行)后,我想在网格中显示一个标签,显示等级(1,2,3,4,5),而不是插入等级的某一行的下拉列表?我很高兴这对您有所帮助。:)将值插入数据库后,是否要用标签替换dropdownlist?@perkes456请参阅编辑。希望它能解决你的问题YES yogi谢谢,不幸的是,我还有另一个问题:(.当一个用户对三种产品进行评分时,另一个用户购买了所有三种相同的产品,现在当他尝试对它们进行评分时,不再显示下拉列表,而只显示评分标签本身(而不是对产品进行评分的下拉列表).我有没有办法将第一个用户的评分踢给第二个用户,这样他就可以输入自己的分数?您是否分别存储每个用户的评分?
     <ItemTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList>
                    <asp:Label ID="lbl_ForDrpdwnVal" runat="server"  Visible="false"></asp:Label>               
    
                        //Access the new label
                        Label lblfordrpdwn= (Label)gridDetaljiNarudzbe.Rows[index].FindControl("lbl_ForDrpdwnVal");
                        lblfordrpdwn.Text= drpdwn1.SelectedItem.Text;//Setting value from dropdown to lbel
                        lblfordrpdwn.Visible=true;//Showing label
                        drpdwn1.Visible=false;//Hiding the dropdown