Gridview Cell可点击。 [英] Gridview Cell clickable.

查看:66
本文介绍了Gridview Cell可点击。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让gridview单元格可以点击,以便从gridview标签获取值,但我目前正在做的是不工作。这是我到目前为止所做的。



I want to make gridview cell clickable so as to get the value from the gridview label but what i am currently doing is not working.This is what i have done so far.

<asp:GridView ID="gvweeklysum" runat="server" CellPadding="4" ForeColor="#333333"
      GridLines="None" Width="465px" AutoGenerateColumns="False" OnRowDataBound="gvweeklysum_RowDataBound">
       <alternatingrowstyle backcolor="White" forecolor="#284775" />
          <editrowstyle backcolor="#999999" />
          <footerstyle backcolor="#5D7B9D" font-bold="True"/>
      <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
      <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
       <pagerstyle backcolor="#284775" forecolor="White" HorizontalAlign="Center"/>
     <rowstyle backcolor="#F7F6F3" forecolor="#333333" />
          <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
          <sortedascendingcellstyle backcolor="#E9E7E2" />
          <sortedascendingheaderstyle backcolor="#506C8C" />
          <sorteddescendingcellstyle backcolor="#FFFDF8" />
          <sorteddescendingheaderstyle backcolor="#6F8DAE" />
      <Columns>
          <asp:BoundField DataField="s008_Weekending" HeaderText="Weekending" InsertVisible="False"
              ReadOnly="True" SortExpression="" />
          <asp:BoundField DataField="s008_hrsday1" HeaderText="Monday" InsertVisible="False"
              ReadOnly="True" SortExpression="" />
          <asp:BoundField DataField="s008_hrsday2" HeaderText="Tuesday" InsertVisible="False"
              ReadOnly="True" SortExpression="" />
          <asp:BoundField DataField="s008_hrsday3" HeaderText="Wednesday" InsertVisible="False"
              ReadOnly="True" SortExpression="" />
          <asp:BoundField DataField="s008_hrsday4" HeaderText="Thursday" InsertVisible="False"
              ReadOnly="True" SortExpression="" />
          <asp:BoundField DataField="s008_hrsday5" HeaderText="Friday" InsertVisible="False"
              ReadOnly="True" SortExpression="" />
          <asp:BoundField DataField="s008_hrsday6" HeaderText="Saturday" InsertVisible="False"
              ReadOnly="True" SortExpression="" />
          <asp:BoundField DataField="s008_hrsday7" HeaderText="Sunday" InsertVisible="False"
              ReadOnly="True" SortExpression="" />
          <asp:TemplateField HeaderStyle-VerticalAlign="Middle">
              <ItemTemplate>
                  <asp:Label ID="lblweekending" runat="server" Text='<%# Eval("s008_Weekending") %>' />
                  <asp:Label ID="lblmonday" runat="server" Text='<%# Eval("s008_hrsday1") %>' />
                  <asp:Label ID="lbltuesday" runat="server" Text='<%Eval("s008_hrsday2") %>' />
                  <asp:Label ID="lblwednesday" runat="server" Text='<%Eval("s008_hrsday3") %>' />
                  <asp:Label ID="lblthursday" runat="server" Text='<%Eval("s008_hrsday4") %>' />
                  <asp:Label ID="lblfriday" runat="server" Text='<%Eval("s008_hrsday5") %>' />
                  <asp:Label ID="lblsaturday" runat="server" Text='<%Eval("s008_hrsday6") %>' />
                  <asp:Label ID="lblsunday" runat="server" Text='<%Eval("s008_hrsday8") %>' />
              </ItemTemplate>
          </asp:TemplateField>
      </Columns>
  </asp:GridView>

推荐答案

我认为如果你实现模板列会更好,在模板列中你需要使用所需的控件。最后需要实现 RowDataBound



I think it would be better if you implement template column and in the template column you need to use required control. Finally it needs to implement RowDataBound

protected void CustomersGridView_RowDataBound(Object sender, GridViewRowEventArgs e)
 {

   if(e.Row.RowType == DataControlRowType.DataRow)
   {
     // Display the company name in italics.
     e.Row.Cells[1].Text = "<i>" + e.Row.Cells[1].Text + "</i>";

   }

 }





谢谢,

Mamun



Thanks,
Mamun


在gvweeklysum_RowDataBound中,为每个单元添加click事件...

这样的东西

In gvweeklysum_RowDataBound, add click event for each of the cell...
something like this
protected void gvweeklysum_RowDataBound(object sender, GridViewRowEventArgs e)
      {
          //Check as data
          if (e.Row.RowType == DataControlRowType.DataRow)
          {
              //add a click event handler
              //This will add one alert to to the first cell
              e.Row.Cells[0].Attributes.Add("onClick", "alert('Cell 0 Clicked');");
              e.Row.Cells[1].Attributes.Add("onClick", "alert('Cell 1 Clicked');");
          }
      }


protected void gvweeklysum_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            LinkButton _singleClickButton = (LinkButton)e.Row.Cells[0].Controls[0];
            string _jsSingle = ClientScript.GetPostBackClientHyperlink(_singleClickButton, "");

            for (int columnIndex = 0; columnIndex < e.Row.Cells.Count; columnIndex++)
            {

                string js = _jsSingle.Insert(_jsSingle.Length - 2, columnIndex.ToString());

                e.Row.Cells[columnIndex].Attributes["onclick"] = js;

                e.Row.Cells[columnIndex].Attributes["style"] += "cursor:pointer;cursor:hand;";
            }
        }
    }
}


这篇关于Gridview Cell可点击。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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