Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 27th, 2007, 02:40 AM
Authorized User
 
Join Date: Jul 2007
Location: Delhi, Delhi, India.
Posts: 24
Thanks: 1
Thanked 0 Times in 0 Posts
Default Item Templates

Hi, to all. I have taken a template column in a datagrid and have inserted image button as an item template. I want when the user click that button it identifies the project code which is bound column where data is coming from database. When he clicks on that image button it should identify the project code of that column and then pass that particular value to session variable and then redirect to the next page where i am using these session variables. Earlier i used select button of the datagrid and used selectedIndexchanged as an event in which i was identifying columns and passing that value to session variables and after passing those values i was redirecting to the next page.

Private Sub dg_summary_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dg_summary.SelectedIndexChanged
    Session("PName") = dg_summary.SelectedItem.Cells(0).Text
    Session("PCode") = dg_summary.SelectedItem.Cells(1).Text
   Response.Redirect("report.aspx")
End Sub

But this logic won't work in case of item templates. Can you tell the possible solution. The only thing i could think of is using
itemcommand as event and then pass the value in e.command argument.


  #2 (permalink)  
Old July 27th, 2007, 03:51 AM
Friend of Wrox
Points: 1,935, Level: 17
Points: 1,935, Level: 17 Points: 1,935, Level: 17 Points: 1,935, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2004
Location: United Kingdom
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
Default

Yes, you are correct. Fetch the value of your project code in the commandArgument property of imagebutton, and then on the ItemCommand event, read this value and set it to the session variable (as per your requirement)...

Regards
Mike

Don't expect too much, too soon.
  #3 (permalink)  
Old July 27th, 2007, 07:30 AM
Authorized User
 
Join Date: Jul 2007
Location: Delhi, Delhi, India.
Posts: 24
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Ya i got nearest to it, but it showing container as undeclared. What type of declaration i should take in this case.

Private Sub dg_summary_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles dg_summary.ItemCommand
        e.CommandArgument(DataBinder.Eval(Container, "DataItem.Pcode"))
End Sub


  #4 (permalink)  
Old July 27th, 2007, 08:50 AM
Friend of Wrox
Points: 1,935, Level: 17
Points: 1,935, Level: 17 Points: 1,935, Level: 17 Points: 1,935, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2004
Location: United Kingdom
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
Default

You have to assign the commandArgument first to the ImageButton in aspx page as below:

<asp:imagebutton commandArgument='<%#DataBinder.Eval(Container, "DataItem.Pcode"))%>' runat=server>

Now in the ItemCommand event, fetch it as below:

Session["Code"] = e.CommandArgument.ToString();

Regards
Mike

Don't expect too much, too soon.
  #5 (permalink)  
Old July 27th, 2007, 09:57 AM
Authorized User
 
Join Date: Jul 2007
Location: Delhi, Delhi, India.
Posts: 24
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Hello, Mike sir
I followed your directions, but on clicking that image button the value
of session variable should have contained P_Id value which is an attribute of Projmaster a table created in SQL server. I took a textbox and passed the value of session variable to it. No value is being passed to it. This is what is have done.

<asp:ImageButton id="imgflag" commandargument='<%#Databinder.Eval(Container,"Dat aItem.P_Id")%>' runat="server" BorderColor="Info" BorderWidth="1px" ImageUrl="flagRed1.gif"></asp:ImageButton>


Session("PCode") = e.CommandArgument.ToString()
textbox1.text = Session("PCode") 'No value is being displayed
Response.Redirect("report.aspx")

When user clicks that image button on a particular row the P_Id value
of that row should go into session variable PCode accordingly on redirecting that value is being used.

  #6 (permalink)  
Old July 28th, 2007, 10:06 AM
Authorized User
 
Join Date: Jul 2007
Location: Delhi, Delhi, India.
Posts: 24
Thanks: 1
Thanked 0 Times in 0 Posts
Default

<ItemTemplate>
<asp:ImageButton id="imgflag" runat="server" BorderColor="Info" BorderWidth="1px" ImageUrl="flagRed1.gif" CommandArgument='<%#Databinder.Eval(Container.Data Item,"P_Id")+Databinder.Eval(Container,"DataItem.P _Name")%>'
CommandName="select"></asp:ImageButton> </ItemTemplate>

When i remove CommandArgument and take <%---%> inside asp tag it displays the values of primary keys of that table. Accordingly the values should be passed to commandargument value in the imagebutton tag, so that i can fetch the value using e.commandargument.string() and then pass the value to session variable, but on clicking the image button no value is being passed to the session variable.
Can anyone help out where i am going wrong.. I want when that image button is clicked the primarykeys values of the datagrid should go into the session variable.

Private Sub dg_summary_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles dg_summary.ItemCommand
        'Response.Write("A ButtonColumn has been clicked!")
        'Dim strTitle As String
        'e.CommandArgument(DataBinder.Eval(Container, "DataItem.Pcode"))
        Session("PCode") = e.CommandArgument.ToString()
       'Session("PName") = e.CommandArgument.ToString()
       'Session("PCode") = dg_summary.SelectedItem.Cells(1).Text
       Label1.Text = Session("PCode")
       'Response.Redirect("Report.aspx")

  #7 (permalink)  
Old August 2nd, 2007, 06:24 AM
Friend of Wrox
 
Join Date: Feb 2006
Location: noida, UP, India.
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to gaurav_jain2403
Default

I think your code for ItemTemplate is not correct. You cannot write + sign there in commandArgument. Try writing it as follow:

<ItemTemplate>
<asp:ImageButton id="imgflag" runat="server" BorderColor="Info" BorderWidth="1px" ImageUrl="flagRed1.gif" CommandArgument='<%#Databinder.Eval(Container.Data Item,"P_Id")%>' CommandName="select"> </asp:ImageButton> </ItemTemplate>

Then in code behind, write as follow :

Private Sub dg_summary_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles dg_summary.ItemCommand
       Session("PCode") = e.CommandArgument.ToString()
       Session("PName") = e.Item.Cells[1].Text
       Response.Redirect("Report.aspx")
End Sub

If this code doesn't run successfully, please try using different command name in place of "Select". Also, tell me what happens.
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Aligning Header & Item DataList Templates rsearing ASP.NET 2.0 Basics 2 October 5th, 2007 06:09 AM
Templates ervinel Classic ASP Basics 0 July 13th, 2006 02:47 PM
Functions in Item Templates wirerider ASP.NET 2.0 Basics 8 March 9th, 2006 12:09 AM
Want Combo Box first item if only 1 item markw707 Access 3 June 9th, 2004 04:03 PM
Find Out First Item of each item Group Jane SQL Language 1 November 22nd, 2003 12:42 PM



All times are GMT -4. The time now is 12:56 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.