 |
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

July 27th, 2007, 02:40 AM
|
|
Authorized User
|
|
Join Date: Jul 2007
Posts: 24
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
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.
|
|

July 27th, 2007, 03:51 AM
|
|
Friend of Wrox
|
|
Join Date: Aug 2004
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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.
|
|

July 27th, 2007, 07:30 AM
|
|
Authorized User
|
|
Join Date: Jul 2007
Posts: 24
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
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
|
|

July 27th, 2007, 08:50 AM
|
|
Friend of Wrox
|
|
Join Date: Aug 2004
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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.
|
|

July 27th, 2007, 09:57 AM
|
|
Authorized User
|
|
Join Date: Jul 2007
Posts: 24
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
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.
|
|

July 28th, 2007, 10:06 AM
|
|
Authorized User
|
|
Join Date: Jul 2007
Posts: 24
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
<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")
|
|

August 2nd, 2007, 06:24 AM
|
|
Friend of Wrox
|
|
Join Date: Feb 2006
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|
 |