PDA

View Full Version : مبتدی: باز شدن پنجره ی جدید بعد از انتخاب دکمه ی ویرایش در گریدویو



panahinia
یک شنبه 16 اسفند 1394, 08:44 صبح
سلام و خسته نباشید

دوستان من می خوام در گریدویو بعد از کلیک بر روی دکمه ی ویرایش صفحه ی ویرایش در یک پنجره ی جدید باز شود ، کدش رو به این صورت نوشتم ولی خطا میده

protected void Grcat_RowDataBound(object sender, GridViewRowEventArgs e)
{



if (e.Row.RowType == System.Web.UI.WebControls.DataControlRowType.DataR ow)
{


LinkButton btn = (LinkButton)(e.Row.FindControl("linkbtnedit"));
btn.Attributes.Add("OnClick", "target='_blank';");


}



}

__________________________________________________ _________

متن خطا :

Server Error in '/' Application.

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:



Line 57:
Line 58: LinkButton btn = (LinkButton)(e.Row.FindControl("linkbtnedit"));
Line 59: btn.Attributes.Add("OnClick", "target='_blank';");




_____________________________________________
قسمت aspx

<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="linkbtnedit" CommandArgument="<%# Container.DataItemIndex %>" CommandName="Edit" runat="server">ویرایش</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>

rezashaban
یک شنبه 16 اسفند 1394, 09:10 صبح
سلام
خب شما نمیتونین روی کلیک Target رو مشخص کنین
الان حضور دهن ندارم ولی اگه LinkButton خصوصیت Target نداره شما از HyperLink استفاده کن و در قسمت Aspx مقدار خصوصیت Target رو براش تنظیم کن

panahinia
یک شنبه 16 اسفند 1394, 09:42 صبح
اگه از hyperlink استفاده کنم اونوقت خاصیت commandargument رو نداره

hamid_0341
سه شنبه 18 اسفند 1394, 02:22 صبح
از لینک باتن استفاده کن و براشcommandname و commandargument قرار بده
<asp:LinkButton ID="LinkButton1" runat="server" CommandArgument='<%# Bind("TicketNumber") %>' CommandName="selectCm" Text="test" ></asp:LinkButton>

و توی رویداد RowCommand
protected void GridView2_RowCommand1(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "selectCm")
{
string id= e.CommandArgument.ToString();
String js = "window.open('../url.aspx" +encid + "', '_blank');";
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "OpenSignature.aspx", js, true);
}
}

panahinia
یک شنبه 23 اسفند 1394, 12:20 عصر
ممنون از راهنمایی شما به این صورت نوشتم ولی خطا میده


protected void Grcat_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Edit")
{
Int32 index = Int32.Parse((string)e.CommandArgument);
string action = "Edit";

string js = "window.open('AddCat.aspx?ID=" + Grcat.DataKeys[index].Values[0] + "&action=" + action + "', '_blank');";
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "AddCat.aspx", js, true);

}


خطا


__________________________________________________ ____________


The GridView 'Grcat' fired event RowEditing which wasn't handled.


Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.


Exception Details: System.Web.HttpException: The GridView 'Grcat' fired event RowEditing which wasn't handled.


Source Error:


An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

hamid_0341
سه شنبه 25 اسفند 1394, 01:48 صبح
ممنون از راهنمایی شما به این صورت نوشتم ولی خطا میده


protected void Grcat_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Edit")
{
Int32 index = Int32.Parse((string)e.CommandArgument);
string action = "Edit";

string js = "window.open('AddCat.aspx?ID=" + Grcat.DataKeys[index].Values[0] + "&action=" + action + "', '_blank');";
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "AddCat.aspx", js, true);

}


خطا


__________________________________________________ ____________


The GridView 'Grcat' fired event RowEditing which wasn't handled.


Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.


Exception Details: System.Web.HttpException: The GridView 'Grcat' fired event RowEditing which wasn't handled.


Source Error:


An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
شما از رویداد RowEditing استفاده کردید ولی توی کد ها اون رو ندارید. میتونید از رویداد های توی گریدویو پاکش کنید مشکل رفع میشه.