ASP.NET GridView模板字段无关的行为 [英] Asp.net gridview template field irrelevant behaviour
问题描述
大家好,
我正在使用C#在Asp.net中创建一个网站,我拥有一个gridview,在该gridview中,我具有用于编辑和删除记录的模板字段..
现在发生的是页面加载时,当我单击该gridview的edit或delete选项,但回发后它起作用了..
我已经使用了这段代码..
Hi everyone,
I am making a website in Asp.net using C#, i have one gridview and in that gridview i have template fields for edit and deleting records..
Now what happens is when page loads and when i click on that gridview''s edit OR delete option but after postback it works..
I have used this code..
<asp:GridView ID="gdvAssetType" runat ="server" AllowPaging="True"
AutoGenerateColumns="False" BackColor="White" BorderColor="#CCCCCC"
BorderStyle="None" BorderWidth="1px" CellPadding="3"
EnableModelValidation="True"
onpageindexchanging="gdvAssetType_PageIndexChanging"
onrowcommand="gdvAssetType_RowCommand" Width="747px">
<Columns>
<asp:TemplateField HeaderText="Sr No.">
<ItemTemplate >
<asp:Label ID="lbSerialNo" runat ="server" Text=''<%#Container.DataItemIndex+1 %>''></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:TemplateField>
<asp:BoundField HeaderText="Asset Type" DataField="AssetType">
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:BoundField>
<asp:TemplateField HeaderText="Edit">
<ItemTemplate >
<asp:ImageButton ID="imgbtnEdit" runat ="server" CommandArgument =''<%#Eval("AssetTypeId") %>'' CommandName ="EditAssetType" ImageUrl ="../_img/ico_edit_new.gif" CausesValidation ="false" ToolTip ="Edit Asset Type"/>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Delete">
<ItemTemplate >
<asp:ImageButton ID="imgbtnDelete" runat ="server" CommandArgument =''<%#Eval("AssetTypeId") %>'' CommandName ="DeleteAssetType" ImageUrl ="../_img/ico_del_new_on.gif" CausesValidation ="false" OnClientClick="if (!confirm(''Do you want to delete this user ?'')) return false;" ToolTip ="Delete Asset Type"/>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="White" ForeColor="#000066" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
<PagerSettings Position="TopAndBottom" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
</asp:GridView>
我的页面加载代码...
My page load code...
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (Session["Username"].ToString() != "" && Session["Username"] != null && Session["Role"].ToString() != "" && Session["Role"] != null && Session.Count != 0)
{
if (!IsPostBack)
{
FillGDVAssetTypes();
}
}
else
{
Response.Redirect("../Login.aspx");
}
}
catch { Response.Redirect("../ErrorPage/Error.aspx"); }
finally { }
//AssignRights();
}
现在在删除模板"字段上单击,它首先会提示用户您是否要真正删除记录",但是在页面加载时不起作用...编辑和删除记录都仅在回发后才起作用...
请帮帮我..
谢谢&问候,
Krunal Panchal
now on delete template field click it first prompts user that "Do you want to really delete the record" , but it doesn''t works on page load ... Both edit and delete record only works after postback...
Please help me out ..
Thanks & Regards,
Krunal Panchal
推荐答案
在更新或删除后的gdvAssetType_RowCommand
方法中,可以调用FillGDVAssetTypes();
方法重新绑定数据.
In yourgdvAssetType_RowCommand
method after update or delete you can callFillGDVAssetTypes();
method to rebind the data.
这篇关于ASP.NET GridView模板字段无关的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!