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]]