| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1252 人关注过本帖
标题:Gridview的CommandFiled的一些小问题
只看楼主 加入收藏
willam
Rank: 1
等 级:新手上路
帖 子:237
专家分:0
注 册:2007-7-13
收藏
 问题点数:0 回复次数:2 
Gridview的CommandFiled的一些小问题
Gridview的CommandFiled的一些小问题,,就是换成buttenType=image之后就不可以了,那个高手能为帮帮忙..

前后gridview的代码:
<asp:GridView ID="GridView1" runat="server" Width="888px" AutoGenerateColumns="False" OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_Rowediting"
     
      OnRowDataBound="GridView1_RowDataBound" >
         <Columns>
              <asp:TemplateField HeaderText="序号">
              <ItemStyle  Width=50px/>
               
             </asp:TemplateField>
             <asp:TemplateField HeaderText="经销商名">
                 <ItemTemplate>
                     <asp:Label ID="Label1" runat="server" Text='<%# Eval("D_shop") %>'></asp:Label>
                 </ItemTemplate>
             </asp:TemplateField>
             <asp:TemplateField HeaderText="经销商电话">
                 <ItemTemplate>
                     <asp:Label ID="Label3" runat="server" Text='<%# Eval("D_tel") %>'></asp:Label>
                 </ItemTemplate>
             </asp:TemplateField>
             <asp:TemplateField HeaderText="经销商QQ">
                 <ItemTemplate>
                     <asp:Label ID="Label4" runat="server" Text='<%# Eval("D_QQ") %>'></asp:Label>
                 </ItemTemplate>
                 <ItemStyle  Width=120px/>
             </asp:TemplateField>
             <asp:TemplateField HeaderText="经销商Email">
                 <ItemTemplate>
                     <asp:Label ID="Label5" runat="server" Text='<%# Eval("D_email") %>'></asp:Label>
                 </ItemTemplate>
             </asp:TemplateField>
             <asp:TemplateField HeaderText="经销商地址">
                 <ItemTemplate>
                     <asp:Label ID="Label6" runat="server" Text='<%# Eval("D_address") %>'></asp:Label>
                 </ItemTemplate>
             </asp:TemplateField>
             <asp:TemplateField HeaderText="经销商图片">
                 <ItemTemplate>
                     <asp:Label ID="Label7" runat="server" Text='<%# Eval("D_path") %>'></asp:Label>
                 </ItemTemplate>
             </asp:TemplateField>
             <asp:CommandField CancelImageUrl="~/images/control/del1.gif" DeleteImageUrl="~/images/control/icon_del.gif"
                 EditImageUrl="~/images/control/icon_edit.gif" HeaderText="操作" ShowDeleteButton="True"
                 ShowEditButton="True" ShowHeader="True" UpdateImageUrl="~/images/control/disk.gif"  />
  //没有ButtonType=""
            
         </Columns>
         <HeaderStyle CssClass="TDHead" HorizontalAlign="Center" />
         
        </asp:GridView>


后台代码:
public partial class admin_sho : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        bind();
      
    }

    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {

       // string alr = "jhkjhjkhkjhkjhkjh";
        //Response.Write(alr);
        string sql = "dfssdfsdfsd";

        Label2.Text = sql;
   
    }
    protected void GridView1_Rowediting(object sender, GridViewEditEventArgs e) {
       // string sql = "delete from shop where id='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
        GridView1.EditIndex = e.NewEditIndex;
        Label2.Text = "哈哈";
        bind();
   
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            ((LinkButton)(e.Row.Cells[7].Controls[2])).Attributes.Add("onclick", "return confirm('确定要删除吗?')");
            //string sqlp = "fdfdmm,.kkljljlkj";
            //Label2.Text = sqlp;
        }
    }


   


    public void bind() {
        getcon dt = new getcon();
        DataSet ds = dt.GetConnString("select * from shop", "shopl");
        // IList<CategoryInfo> cateList = Category.Init().GetCategoryList();
        //I
        GridView1.DataSource = ds.Tables["shopl"].DefaultView;
        GridView1.DataKeyNames = new string[] { "id" };
        GridView1.DataBind();
        int b = ds.Tables["shopl"].Rows.Count;
        for (int i = 0; i < b; i++)
        {
            GridView1.Rows[i].Cells[0].Text = i.ToString();

        }
      
    }
}

[[it] 本帖最后由 willam 于 2008-2-22 13:53 编辑 [/it]]
搜索更多相关主题的帖子: CommandFiled Gridview Width asp 
2008-02-22 13:47
willam
Rank: 1
等 级:新手上路
帖 子:237
专家分:0
注 册:2007-7-13
收藏
得分:0 
这样改之后,,

前后gridview的代码:
<asp:GridView ID="GridView1" runat="server" Width="888px" AutoGenerateColumns="False" OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_Rowediting"
     
      OnRowDataBound="GridView1_RowDataBound" >
         <Columns>
              <asp:TemplateField HeaderText="序号">
              <ItemStyle  Width=50px/>
               
             </asp:TemplateField>
             <asp:TemplateField HeaderText="经销商名">
                 <ItemTemplate>
                     <asp:Label ID="Label1" runat="server" Text='<%# Eval("D_shop") %>'></asp:Label>
                 </ItemTemplate>
             </asp:TemplateField>
             <asp:TemplateField HeaderText="经销商电话">
                 <ItemTemplate>
                     <asp:Label ID="Label3" runat="server" Text='<%# Eval("D_tel") %>'></asp:Label>
                 </ItemTemplate>
             </asp:TemplateField>
             <asp:TemplateField HeaderText="经销商QQ">
                 <ItemTemplate>
                     <asp:Label ID="Label4" runat="server" Text='<%# Eval("D_QQ") %>'></asp:Label>
                 </ItemTemplate>
                 <ItemStyle  Width=120px/>
             </asp:TemplateField>
             <asp:TemplateField HeaderText="经销商Email">
                 <ItemTemplate>
                     <asp:Label ID="Label5" runat="server" Text='<%# Eval("D_email") %>'></asp:Label>
                 </ItemTemplate>
             </asp:TemplateField>
             <asp:TemplateField HeaderText="经销商地址">
                 <ItemTemplate>
                     <asp:Label ID="Label6" runat="server" Text='<%# Eval("D_address") %>'></asp:Label>
                 </ItemTemplate>
             </asp:TemplateField>
             <asp:TemplateField HeaderText="经销商图片">
                 <ItemTemplate>
                     <asp:Label ID="Label7" runat="server" Text='<%# Eval("D_path") %>'></asp:Label>
                 </ItemTemplate>
             </asp:TemplateField>
             <asp:CommandField CancelImageUrl="~/images/control/del1.gif" DeleteImageUrl="~/images/control/icon_del.gif"
                 EditImageUrl="~/images/control/icon_edit.gif" HeaderText="操作" ShowDeleteButton="True"
                 ShowEditButton="True" ShowHeader="True" UpdateImageUrl="~/images/control/disk.gif" ButtonType="Image" />
//ButtonType="Image"             
         </Columns>
         <HeaderStyle CssClass="TDHead" HorizontalAlign="Center" />
         
        </asp:GridView>

后台代码:
public partial class admin_sho : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        bind();
      
    }

    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {

       // string alr = "jhkjhjkhkjhkjhkjh";
        //Response.Write(alr);
        string sql = "dfssdfsdfsd";

        Label2.Text = sql;
   
    }这句就不执行了



   protected void GridView1_Rowediting(object sender, GridViewEditEventArgs e) {
       // string sql = "delete from shop where id='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
        GridView1.EditIndex = e.NewEditIndex;
        Label2.Text = "哈哈";
        bind();
   
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            ((ImageButton)(e.Row.Cells[7].Controls[2])).Attributes.Add("onclick", "return confirm('确定要删除吗?')");
            //string sqlp = "fdfdmm,.kkljljlkj";
            //Label2.Text = sqlp;
        }
    }

[[it] 本帖最后由 willam 于 2008-2-22 13:54 编辑 [/it]]
2008-02-22 13:50
willam
Rank: 1
等 级:新手上路
帖 子:237
专家分:0
注 册:2007-7-13
收藏
得分:0 
谁能回一下啊
2008-02-22 15:35
快速回复:Gridview的CommandFiled的一些小问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018316 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved