如何在Gridview中以唯一的ID&单击图像从单元格获取ID [英] How to Add Images like ImageButtons in Gridview all cells dynamically with unique ID & get ID's from cell when we click on image

查看:89
本文介绍了如何在Gridview中以唯一的ID&单击图像从单元格获取ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
我正在开发电影院座位预订网站,例如 www.bookmyshow.com [

Hi to all
I am developing movie theater seat booking website like www.bookmyshow.com[^], for that i have place image as Seats in asp:gridview(all cells), for selection of seat click on Image(cell) at that time i need that cell value(Seat No) where i clicked Image(cell) in gridview.

This binding based on Database
In Database Cell value=0 Then in gridviewCell no image
In Database Cell value=1 Then in gridviewCell image indicate available Seat
In Database Cell value=2 Then in gridviewCell image indicate Selected Seat
In Database Cell value=3 Then in gridviewCell image indicate Booked Seat

This Database is every time changes by selecting deferent Theater.
So theater layout is not fix to some Rows & Columns,
so this all binding is done dynamically.

If possible send me Sample code.

Please help me.

推荐答案

就获取单元格值而言,也许 ^ ]可以为您提供帮助.
As far as getting cell values is concerned, maybe this[^] can help you out.


您可以添加ImageButton控件而不是简单的Image控件,ImageButton控件还有一个名为CommandParameter的附加属性,可以与您的customId(在添加到网格单元时说出SeatNo),

每当您单击按钮时,就会发生事件冒泡并执行Gridview1_ItemCommand事件,在该事件处理程序中,您可以识别通过其CommandParameter属性单击了哪个ImageButton.
You can add ImageButton control instead of simple Image control, the ImageButton control has an additional property called CommandParameter which you can bind with your customId (Say SeatNo) while adding to grid cells,

Whenever you will click the button, event bubbling will happen and Gridview1_ItemCommand event will be executed, in that event handler you can identify, which ImageButton is clicked through its CommandParameter property.


您好,

我尝试了一些符合您要求的代码

检查我的代码

Hi

I tried some code for your requirement

Check my code for it

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script language ="javascript" >


    
    </script>
</head>
<body >
    <form id="form1" runat="server">
    <div>
        <asp:datalist id="DataList1" runat="server" repeatcolumns="5" xmlns:asp="#unknown">
            RepeatDirection ="Horizontal" onitemcommand="DataList1_ItemCommand" 
            onitemdatabound="DataList1_ItemDataBound" >
        <HeaderTemplate >
        </HeaderTemplate>
        <itemtemplate>
         <table width="20" height="20">
          <tr>
            <td>
                <asp:linkbutton id="LinkButton1" runat="server" commandname="book" commandargument="<%#Eval("vid") %>"><img src="Images/Winter.jpg" width="19" height="19" /></asp:linkbutton>
            </td>
          </tr>
         </table>
        </itemtemplate>
        <footertemplate>
        
        </footertemplate>
        </asp:datalist>
    </div>
    </form>
</body>
</html>



并且文件后面的代码包含以下代码



And code behin file contains following code

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        MylocalDataClassesDataContext db = new MylocalDataClassesDataContext();
        var g = from d in db.VideoTabs
                select d;
        DataList1.DataSource = g;
        DataList1.DataBind();
    }
}

protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
    if (e.CommandName == "book")
    {
        // write for booking here
    }
}
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
        LinkButton rdblist = (LinkButton)e.Item.FindControl("LinkButton1");
        //check database values here

        rdblist.Text = "<img src="\"Images/Waterlilies.jpg\"" width="\"19\"" height="\"19\"" />";
    }
}


在这里,您必须检查数据绑定事件中的数据库值
希望您能理解我的所作所为.

最好的


Here you''ve to check the database values in databound event
I hope you can understood What I did.

All the Best


这篇关于如何在Gridview中以唯一的ID&amp;单击图像从单元格获取ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆