I have list view with multiple lines and in every line I have textbox where is number of items in cart and refresh button. So if someone change number of items and click on update, I wanna change it in cookie and db. Im using CommandArgument where 1 parameters is ID of row in table between tableProduct and tableCart and second i wanna sent current value of textbox, where is how many items user wanna buy, but i dont know how to add. Can u help me?
<asp:TextBox runat="server" id="countInCart" Text='<%# Eval("countInCart") %>' /><asp:ImageButton ID="ImageButton1" runat="server" ImageAlign="AbsBottom" ImageUrl="~/Static/Img/inp-order-refresh.png" OnCommand="updateClick" CommandArgument='<%# Eval("id") + ";" + **here i want add value of countInCart, but I dont know how** %>' />
you are looking for a way to update them in bulk. have a look at this; http://geekswithblogs.net/thanigai/archive/2009/05/21/bulk-insert-update-and-delete-with-asp.net-listview-control.aspx
Related
I want to make a link detail from database, I use linkbutton on templatefield gridview to go to the database details according to each id, I use like code below method works properly but when I filter the result and click certain row, the Id received in the server end seems to be different not corresponding to what I clicked. I feel it gets the wrong row index... this happens only when I try filtering and perform row command click. Other wise it works properly. Why is this.
<asp:TemplateField HeaderText="Nama File" ItemStyle-Width="300px">
<ItemTemplate>
<asp:LinkButton ID ="InkView1" runat ="server" Text='<%# Eval("ID") %>' CommandArgument='<%#Eval("ID") %>' OnCommand="linkDownloadFile1_Click"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
code behind
int ImageId = Convert.ToInt32((sender as LinkButton).CommandArgument);
I have created a bulk edit gridview using Itemtemplate for each column. Label for non-edit mode, Textbox for edit mode. But this works only if the structure of gridview is known(Defining templates in asp).
<asp:TemplateField HeaderText="Name" ConvertEmptyStringToNull="True">
<ItemTemplate>
<asp:Label ID="lblName" Visible='<%# !(bool) IsInEditMode %>' runat="server" Text='<%# Eval("name") %>' />
<asp:TextBox ID="txtName" ControlStyle-CssClass="wide" Visible='<%# IsInEditMode %>'
runat="server" Text='<%# Eval("name") %>' />
</ItemTemplate>
</asp:TemplateField>
Now, what I am trying to achieve is when the user selects a dropdown value, the sql query is fired and it returns result. And this result is shown in gridview. But the problem arises because the number of columns in the result for each selected value from dropdown may vary. And i want to make the gridview as editable(or read-only). This requires two templates to be defined for each column.
So i want to know how this can be done dynamically i.e defining templates depending on number of columns returned by sql.
First off, you could trigger the query and following code with this event.
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
//insert code
}
For the issue of different templates, I might suggest using two GridViews. I've done this where I have two separate sets of results. If they choose a dropdownItem, it hides GridView1 and shows GridView2 (while querying GridView2.SqlDataSource).
Now are you querying different SQL Tables based on dropdown? Or are they querying from the same place?
I have a ListView that I populate from the database. The ListView has a Checkbox on each row which is a built-in property of ListView.
I have been trying to get the text from the ID column next to the Checkbox which I will use in deleting the respective rows from the database but it all fails. I thought I could get the ListView.CheckedIndices and use them in return to point to the SelectedText of each index.
However all fails. More specifically i wanted to use the OnItemDeleting Event of list view but the ListView I have does not seem to have such event.
Is there any way i can achieve this?
I have had this problem before. What I did was this below:
<asp:ListView ID="xyz" runat="server">
<ItemTemplate>
<asp:LinkButton runat="server" ID="blah" OnClick="blah_Click"
CommandArgument="<%# myObject.Id %>" />
</ItemTemplate>
</asp:ListView>
I got the passed id through the command argument.Then I deleted the selected item and refreshed the data for listView. I am sure there must be a cleaner way of doing it.
Let me know how it goes.
I need some help with the following.
I have a list view that I fill with code-behind:
Linq->Sql:
ListView1.DataSource = from x in database.ITEMS
select x;
ListView1.DataBind();
Content of ITEMS:
ID
Name
Quantity
I only show the name of the fields:
<tr>
<td>
<asp:Label ID="nameLabel" runat="server" Text='<%# Eval("Name") %>' />
</td>
</tr>
Assuming I have 25 rows in the database, I fill the list view with 25 rows. Next is what I need help with. The user needs to click one of the 25 names (complete row) and redirects to a page where the content of that row is showed. So lets say someone clicks on "Cars", he'll be redirected and he will see: You have selected Cars, Cars has an ID of 19 and a Quantity of 6.
I have browsed the Internet already but I am having trouble finding solutions that I can understand. I am kind of a noob when it comes to list views and other data displaying methods.
My 2 questions:
How do I start a event when I click a row (and not a button or a link in that row)?
When I click a row and start a event, how can I check which one was clicked?
I hope someone can explain to me how this is done in a user friendly noob kind of way or redirect me to a tutorial discussing my issue's and also in a user friendly way. Thanks in advance.
Ok - I am not sure if this is the best way to go with this (I'll be interested what other think)... but this will work .
Update your listview to something like this:
<script type="text/javascript">
// simple redirect to your detail page, passing the selected ID
function redir(id) {
window.location.href = "mydetailpage.aspx?id=" + id;
}
</script>
<table>
<asp:ListView ID="ListView1" runat="server">
<ItemTemplate>
<tr onclick="redir('<%# Eval("ID") %>');">
<td>
<asp:Label ID="nameLabel" runat="server" Text='<%# Eval("Name") %>' />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
</table>
Then create another page to show your detail (e.g. mydetailpage.aspx) - this should requery your database and show the other fields, given the id passed in the querystring.
you can define onclick attribute to call javascript function on tr element like this :
onclick="yourfunction('<%# Eval("Name") %>');"
Then you can put anything in your javascript function like redirect to another page
I saw few grid view examples where data is bound to grid view from a sql or other database. The question is -
<ItemTemplate>
<asp:Label ID="label1" runat="server" Text='<%#Bind("name") %>'>
</asp:Label>
</ItemTemplate>
How is Text='<%#Bind("name")%>' working? From where does the label gets the text?
I am using mysql I have a drop down list of tables, and a button. Whenever the user selects any table from ddl, and clicks on the button, I will bind the selected table with the grid.
I have enable autogenerating=true for edit and delete buttons.
I will write code for that, but whenever the user selects a different table will the grid show edit and delete buttons? and what about the Bind("value") ? will it change for every table?
Might be a silly question but please help!
The #Bind("name") command will insert the value of the column named name from whichever table you're binding to the GridView. Therefore, each of your tables would need a column named name for this label to be populated.
Also, #Bind should be used for both displaying and updating data. If you only need to display data, #Eval("name") is a better choice, as this is read-only.
you have to use the #Eval, for example,
<EditItemTemplate>
<asp:Label ID="lbleditusr" runat="server" Text='<%#Eval("Username") %>'/>
</EditItemTemplate>