GridView CommandArgument Needs Field From Repeater
Sep 4, 2014
I have a repeater. This gets bound to a data set which contains (amongst others) a field called EntityType and a field called ID. An Entity Type might be "Person" and there might be several categories of "Person". The ID field identifies that category. So there might be a "Person" type 1, a "Person" type 2 and so on. The Entity Type and ID therefore make up a compound primary key.
Nested in each row of the repeater I have a grid view which get populated as a result of clicking an "expand" button in the repeater row. Each row in the GridView represents an "Entity". So "Peter" who's own ID might be, say 59 might be a "Person" of Type 1. So Peter really has a three column primary key consisting of the EntityType and ID field's from the repeater's dataset and the ID from gridview's dataset.
So in order to query the database and fully retrieve Peter, I need that whole primary key. I know how to get the ID from the GridView's dataset, I set Eval("ID") as the CommandArgument for the gridview's button and then consume it in the event. But I don't know how to get at the EntityType or the ID from the Repeater's dataset. How can I do that?
Here's my code at the moment:-
asp Code:
<asp:Repeater ID="ChildClassesRepeater" runat="server" OnItemCommand="ChildClassesRepeater_ItemCommand" Visible ="false" >Â Â Â Â
<ItemTemplate>Â <tr> <td>Â <%# DataBinder.Eval(Container.DataItem, "EntityType")%>Â </td>Â <td>Â
<%# DataBinder.Eval(Container.DataItem, "Class")%>Â </td> <td>
[Code] ....
I'm thinking the easiest thing to do is put the EntityType and parent ID on the Command Argument where it currently reads IDontKnowWhatGoesHere but I can't work out how to get at them.
Alternatively, is there a way I can get at them in the event handler? I think not but I'm not sure.
I could have the query for the grid view return the parent columns, that would allow me to eval them in the same way as I am the entity ID. That feels like I'm reading redundant data, though, as it's already there in the client - if I could just get at it.
View 10 Replies
Similar Messages:
Oct 15, 2010
The link button only sets some value as true and does nothing else. When I run the code the LinkButton's event just won't fire! In my aspx page I got this LinkButton inside of a repeater with CommandName="SetDefault", some ID, runat property. That's it. In my code, inside of myRepeater_Itemcommand(), I got this
if (e.CommandName == "SetDefault")
{
Users obj = new Users();
obj.IsDefault = true;
}
[EDIT] I resolved it myself. It was a silly mistake. "l" was missing from "SetDefault" in my aspx page.
View 1 Replies
Feb 10, 2011
can i add commandname or commandargument to a checkbox-control in a gridview?
View 5 Replies
Mar 5, 2010
I have a gridview with multiple rows, each has a Update button and I need to pass 2 values when someone clicks on Update button. Aside from packing the arguments inside CommandArgument separated by commas (archaic and not elegant), how would I pass more than one argument?
<asp:LinkButton ID="UpdateButton" runat="server" CommandName="UpdateRow" CommandArgument="arg_value" Text="Update and Insert" OnCommand="CommandButton_Click" ></asp:LinkButton>
As a note, the values can't be retrieved from any controls on the page, so don't offer any design solutions. Please concentrate on the question asked.
View 2 Replies
Apr 21, 2010
I have nested a repeater control in Gridview. Right now it is showing gridview rows and repeater header for every case(whether data is there or not for that particular grid view row in the repeater control). I want to hide the gridview row and repeater control header when there is no data present for that particular gridview row. That case I handled at code level by filtering the resulted data table.
Now the another problem I am facing: I have allowed the paging on the gridview i.e. pagesize 3. When page loads it works fine, but when I go to page 2 then it generates following error: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
Below is the code to fill the grid, paging and fill repeater on rowdatabound event of grid.
[code].....
View 1 Replies
Jan 20, 2011
I have a gridview and I have a link button that fires the onrowcommand event. In the method I have
protected void SelectCreditCard(object sender, GridViewCommandEventArgs e)
{
int index = Convert.ToInt32(e.CommandArgument);
}
But I get the error input string in incorrect format.
View 5 Replies
Dec 1, 2010
I have GridView in UserControl (ascx) who is in another ascx.
[Code]....
View 2 Replies
Jan 29, 2010
I have a gridview set up as follows:
[Code]....
Now, as you can see I've set up the commandargument, and was expecting to get to that in my code behind file. My code is as follows:
[Code]....
Ok...so far so good, and as long as I'm the only one working on the system it works fine. The problem is if this scenario happens:
* I go to the page and look at the gridview
* Someone else enters a new record into the database, causing the first row to contain a new record (not displayed in my browser)
* I click select.
What happens then is that, for some odd reason, I will get n numbers higher than the one I actually selected (n = num_added -num_removed).
I was under the impression that the commandargument wouldn't change for my session as long as I didn't refresh the gridview...?... There are no ajax or anything else messing with postbacks or viewstate as far as I can see..
View 5 Replies
Jun 11, 2010
I want to hyperlink from a field in one gridview to a field in another gridview based on id. I've tried many ways but haven't seen success.
View 20 Replies
Nov 28, 2010
i use div and repeater to show categories for searching part. there is a div. when iclick it, repeater opens and if i select a category its name shows on div. this part is ok. Now i do searcing. so i have to take the span's value(or repeater's value).
View 2 Replies
Jan 14, 2010
How can I format my date field like this "Jan 6 @ 7:42 AM" from my date field. My present date field is in this format "1/6/2010 7:42:00 AM".
I am using this in my repeater control.
View 2 Replies
Apr 11, 2010
I'm trying to retrieve the value of the "ListName" field that was clicked in the repeater but I'm getting null ("") in "ListTitle", please could someone correct my code:
Protected Sub repTriggers_ItemCommand(ByVal sender As Object, ByVal e As RepeaterCommandEventArgs)
Dim ListTitle As String
If e.CommandName = "trigger" Then
ListTitle = CType(e.Item.FindControl("lnkTrigger"), LinkButton).Text
[Code]....
View 1 Replies
Jan 26, 2011
nested repeater like this:
<asp:Repeater ID="repeaterReportListByJob" runat="server" DataSource='<%# GetReportsByJobNID(Eval(Container.DataItem, "JobNID")) %>'>
It seems my Eval(Container.DataItem, "JobNID") is not working and I assume this is because the datasource of the outer (parent) repeater is an anonymous type. So how am I supposed to access a particular field of my anonymous type?
View 7 Replies
Aug 20, 2010
I have repeator control that is bind to a datareader.
[Code]....
Now here the Aritcle field contain text that include the html tags as well.
What i want is to display 100 characters from it, along with more href link at the end.
View 4 Replies
Mar 19, 2011
How do I text the string length of a field value in a repearter.
<asp:HyperLink ID="hypName12" runat="server" Visible='<%# (Convert.ToString(Eval("L_Name")) Length > 5 ) %>' ImageUrl="~/name12.gif" NavigateUrl='<%#
"http://" + Eval("L_Name") %>' Target="_blank" ></asp:HyperLink>
View 2 Replies
Jun 28, 2010
I have a repeater control and inseid it's ItemTemplate and AlternateItemTemplate, I have the following code (toy code):
[Code]....
The problem is, when I click the button it shows a '*' in front of every textbox in odd or even items, instead of validating only the textbox in that item.
How can I validate only the text box inside the item in which the button being clicked resides?
View 2 Replies
Jul 9, 2010
I have 2 fields in my gridview one called ScriptType the other BagNo, when a user click the edit button, I would like the BagNo filed to be disabled if the ScriptType field is = "TTA" and enabled otherwise. How can I do this?..something along these lines see below..I am using VB..
[code]...
View 14 Replies
Dec 19, 2010
I have a grid view, and I add new column as a hyper link field, I want the navigationURL for this field to be Pageexample.aspx?ID=other field value like this
[code]...
is that possible ?
View 2 Replies
Jul 13, 2010
I´m trying to use ImageButton to link to another page. ImageButton is inside a Repeater and the code is following:
<ul id = "ulMap">
<asp:Repeater ID="Repeater1" runat="server" >
<ItemTemplate>
<li>
<asp:ImageButton ID="ImageButton1"
CommandArgument='<%#Eval("Nav_ID") %>'
runat="server"
[code]...
View 3 Replies
Dec 7, 2010
I'm using the commandArgument property of the LinkButton ( Which is wrapped inside a repeater ) to pass two values -as one string- to a second repeater then I try to split them into two values, So I could use them as parameters in my ADO.NET Code (SqlCommand Parameters)....after testing my queries don't return any results but If I passed fixed values for the parameter or change the source of the parameter (just for test from a textbox or querystring or something) I get my results, so I think the problem is in splitting.
I Conduct some arugment values from the ArgumentCommand property of the LinkButton -which is wrapped inside a repeater:
<ItemTemplate>
<asp:LinkButton id="sort_lnkbtn" Text='<%# Eval("value")%>'
CommandArgument='<%#string.Format("{0}|{1}",Eval("arrange_by_id"),Eval("value"))%>' runat="server">
</asp:LinkButton>
</ItemTemplate>
Then I receive these values and cut them into two pieces of information:
string sortByAndArrangeBy = (e.CommandArgument).ToString();
char[] separator = { '|' };
string[] sortByAndArrangeByArray = sortByAndArrangeBy.Split(separator);
Now the ado.net code uses this values as a
using (SqlConnection cn1 = new SqlConnection(ConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString))
{
using (SqlCommand cm1 = new SqlCommand("SELECT [name] FROM brands WHERE (name like @SearchString + '%' )", cn1))
{
cm1.Parameters.Add("@SearchString", System.Data.SqlDbType.Char);
cm1.Parameters["@SearchString"].Value = sortByAndArrangeByArray[1];
cn1.Open();
using (SqlDataReader dr1 = cm1.ExecuteReader())
{
List_rpt.DataSource = dr1;
List_rpt.DataBind();
}
}
}
View 1 Replies
Jan 27, 2011
I have a web page that has a repeater bound to a data source. I beed to change a label inside the repeater based on the data that is in each repeater item. For instance, for the first item it might be one thing, and for the next item the label may be something else. I am currently doing some processing in the prerender event, but I don't know if I can or how to access the data source fields there. Where and how do I get access to the data in each item so I can change the label text?
View 3 Replies
Mar 10, 2010
I have a ImageButton in a for loop
[Code]....
How do I set the CommandArgument? The above code does not work and how to do this.
View 1 Replies
Nov 23, 2010
For a given MS SQL Database table of staff members, I'm using ASP to display each record line by line as follows:
So I've added 2 ImageButtons in an extra column and the problem I have is passing the record id as a CommandArgument to redirect to a secure page where the record can be edited or deleted.
Here's some code:
[Code]....
[Code]....
ctdRdr(0) evaluates to the ID value for the the record. )
When I click on the 'Delete' ImageButton the URL in the Response.Redirect becomes:
ctdirectory_secure/deletemember.aspx?id=<%@%20ctdRdr(0)%>
instead of, say:
ctdirectory_secure/deletemember.aspx?id=435
I'm assuming that a <%= expression %> cannot be used to set a control parameter, but how else can I do it?
View 5 Replies
Mar 12, 2010
I'm wondering how is CommandArgument of a button passed to handler at low level.For example if I need to pass few values in CommandArgument what is better - to make it like 134_3554_345 and then parse or to pass an instanse of class like new MyClass(135,3554,345) ?
View 1 Replies
Mar 14, 2011
I need some high-level advice on how to deal with this issue. I want to have dynamically created buttons, each with a different CommandArgument, that call an OnCommand event when clicked. Given that these are dynamic buttons, I have to re-create them in Page_Load after the postback. However, when I re-create the buttons, the orginal command arguments are lost, and the arguments generated after the postback are only valid.As you'd expect, if I don't recreate the buttons, the event handler is never called because the buttons don't exist.My question is, how can I retrieve those original commandarguments, without the use of sessions.
View 6 Replies