使用数据库中的计数将图像动态绑定到gridview

编程入门 行业动态 更新时间:2024-10-24 18:25:56
本文介绍了使用数据库中的计数将图像动态绑定到gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

您好,专家... 我在这里要动态地将图像绑定到gridview.我需要的是我必须动态地将图像与数据库中的计数绑定在一起,即在plotdetails表中,如果项目中有10个地块,那么我必须将出售的地块绑定为红色网格中的图像.. 我写了一些代码,但是我陷入了绑定网格视图中的图像的问题.这是我的代码.

Hi Experts... I am here to bind images to gridview dynamically.. What i need is i have to bind image dynamically with a count in database i.e. in plotdetails table if there is a 10 plots in a project then i have to bind the sold plots in red colour image in grid.. i wrote some code but i stuck in bind the images in gridview... here is my code...

protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e) { Sold_Update(); }

public DataSet Sold_Update() { cmd = new SqlCommand("Select count(Plotid) from Mas_PlotDetails where Projid='" + DropDownList1.SelectedItem.Text + "'and Sold_Status=1", con); cmd.CommandType = CommandType.Text; cmd.Connection.Open(); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds, "Mas_PlotDetails"); return ds; }

我需要的是,如果已出售该地块,则必须进行地块计数并将红色图像绑定到网格中,否则,如果该地块未出售其他颜色,则将其绑定在网格中.我必须将计数图的编号绑定为网格中的图像. 我现在完成了以下代码...它显示了图像..但是我应该按照计数循环显示图像..如何执行此操作... 受保护的void GridView1_RowDataBound(对象发送者,GridViewRowEventArgs e) { 如果(e.Row.RowType == DataControlRowType.DataRow) { DataRowView dr =(DataRowView)e.Row.DataItem; 字符串myflag = dr ["Plotid"].ToString(); 如果(myflag!="0") { e.Row.Cells [1] .Controls.Clear(); ImageButton img =新的ImageButton(); img.ImageUrl =〜/Images/wchair.jpg"; for(int i = 0; i<; i ++)//这里是如何循环myflag以使计数为10,我要显示10张图像 { e.Row.Cells [1] .Controls.Add(img); } }

What I need is to have to take the plot counts and bind the red colour image in grid if the plot is sold otherwise if the plot is not sold some other colour. I have to bind the no of counts plot to as image in grid. I done the following code now... its shown the image.. but i should loop the image as per the count.. How to do this... protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { DataRowView dr = (DataRowView)e.Row.DataItem; string myflag = dr["Plotid"].ToString(); if (myflag != "0") { e.Row.Cells[1].Controls.Clear(); ImageButton img = new ImageButton(); img.ImageUrl = "~/Images/wchair.jpg"; for (int i = 0; i < ;i++ ) // Here how to loop the myflag so that the count is 10, i hav to display the 10 images { e.Row.Cells[1].Controls.Add(img); } }

推荐答案

正常绑定网格视图,并格式化gridview的RowDataBound事件内部的行,将数据绑定到该行后,将针对每一行执行此事件. > Bind your gridview normally, and format the rows inside RowDataBound event of gridview, this event is executed for each rows after binding the data to it. void productsGridView_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { // determine the value of the UnitsInStock field int unitsInStock = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "UnitsInStock")); if (unitsInStock == 0) // color the background of the row Red e.Row.BackColor = Color.Red; else e.Row.BackColor = Color.Green; } }

更多推荐

使用数据库中的计数将图像动态绑定到gridview

本文发布于:2023-10-16 00:34:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1495950.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库中   绑定   图像   动态   gridview

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!