Logo 
Search:

Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

Link buttons on DG

  Asked By: Cameron    Date: Mar 30    Category: Asp.net    Views: 1166
  

The very first row I have has a "add new row" link button I have images for when the any row in is in edit mode i.e. a disk image for update and a X image for cancel But I want to be exclude the first row from having the images and they must have the default text when in edit mode , i.e. insert and cancel, any other row when in edit mode must have the images.

Share: 

 

4 Answers Found

 
Answer #1    Answered By: Aaleyah Khan     Answered On: Mar 30

I think you just have to do a load of "if then"'s


<tr>
<td valign="middle" class="text">
<% if (staff){ %>
<asp:Button id="Button1" class="edititem" runat="server" Text='<%# ((string)DataBinder.Eval(Container.DataItem, "itemid")).Trim()%>' onmouseover="this.className='edititemover'" onmouseout="this.className='edititem'" commandname="Edit" />
<% } else { %>
<%# DataBinder.Eval(Container.DataItem, "itemid")%>
<% } %>
</td>
</tr>

is what I did once upon a time.

Also a neat trick is

<%# MySupp((string)DataBinder.Eval(Container.DataItem, "suppname"))%>

where MySupp is a function and so you can generate a load of <tr><td>'s from code behind based on the bound value "suppname".

 
Answer #2    Answered By: Marta Kim     Answered On: Mar 30

what I am doing now is on the edit  mode if the selection clicked is = Add row  I am setting a public Boolean var to true then in the update  cmd I check for that var to be either true or false and based on that I am doing something BUT

IN my edit cmd I have


If CType(e.Item.Cells(1).Controls(1), LinkButton).Text = "Add New" Then

Addrow = True

Response.Write(Addrow clicked)

End If


Then in my update command I am doing:

Response.Write(Addrow)

If Addrow = True Then

Response.Write("True")

ElseIf Addrow = False Then

Response.Write("False")

End If

I know I can simplify that saying If addrow then but!!!!


It always sets itself to false EVEN if I click on add  row which is suppose to set the public var to true....

WHY what am I doing wrong here?

 
Answer #3    Answered By: Shaun Thomas     Answered On: Mar 30

Maybe change Page_Load into Pre_Render .... though I wouldn't if you can keep it all in Page_Load

there's loads of thing sit could be. Try setting it in ViewState and even holding it as a session var - but it can get tricky.

If you bind all of your data in a function then call that function again within the edit  and update  commands.


public void List_Edit(Object sender, DataListCommandEventArgs e)
{
list.EditItemIndex = (int)e.Item.ItemIndex;
//BindPagedData();
string itemID = list.DataKeys[list.EditItemIndex].ToString();
double price;
int qty;
string itemName;
string sItemDescn;
int discount;
string disctype;
string img;
bool inStock;

// get details about item
Item item = new Item();
item.GetDetails(itemID, out price, out qty, out itemName, out sItemDescn,
out discount, out disctype, out img);
//inStock = qty > 0 ? true : false;
//Change this as I shall be adding up the items purchased, starting at zero.
inStock = qty > -1 ? true : false;

//Response.Write("itemID : " + itemID + " price : " + price + " itemName : " + itemName + " itemDescn : " + sItemDescn + " img : " + img);

Session["currentSubItem_R"] = "..... " + sItemDescn + " is in <b>edit</b> mode.";
ViewState["currentSubItem_L"] = Session["currentSubItem_L"];
ViewState["currentSubItem_R"] = Session["currentSubItem_R"];
currentPage = (int)ViewState["CurrentPage"];
currentItem = (string)ViewState["CurrentItem"];
currentSubItem_L = (string)ViewState["currentSubItem_L"];
currentSubItem_R = (string)ViewState["currentSubItem_R"];
BindPagedData(); ....................................................................this is my main function that binds all the data ... it is also called from page Load
}

private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
currentPage = 1;
BindPagedData();
}
}


when you response.Write(Addrow) what does it print out ?
You just need to get the whole pages structure regards load order and postbacks and events in the correct order.

Binding in Pre_Render may do it - but if you get into that habit you end up loosing a bit of leaway when it comes to importing and nesting controls in a page.

 
Answer #4    Answered By: Akins Massri     Answered On: Mar 30

i've some similar experiences, and don't know how it comes, but gloval var's are not always working very well as you want...
Sounds maybe stupid, but maybe you can try a hidden field or Session...

 
Didn't find what you were looking for? Find more on Link buttons on DG Or get search suggestion and latest updates.




Tagged: