boneythomas
asked on
link button inside a repeater
I have a linkbutton inside a repeater. in my aspx.cs page I need to write a event handler for the linkbutton. by this click event I need to redirect the link to a different location. I am not able to call the linkbutton id. could you just help me out here. I am using the link button because i need to update a table on the click of the button. That's the reason why i am not using the hyperlink.Could you please help me out...I have attached my aspx page where the linkbutton code is written
<asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound" DataSourceID ="ViewDocuments" OnItemCommand="Repeater1_ItemCommand">
<HeaderTemplate><table></HeaderTemplate>
<ItemTemplate>
<tr><td><asp:LinkButton
ID="lnkFilename" runat="server" Text='<% # Eval("DocumentName")%>' ></asp:LinkButton>
</td></tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
ASKER
thank you..I had thought of it..I will try this and then let you know..
Actually it's not quite right.
You create an event handler in code behind fro the repeate like this:
MyRepeater.ItemCommand += new RepeaterCommandEventHandle r(Test);
Then create an event handler like this:
public void Test(object sender, CommandEventArgs e)
{
Response.Write(e.CommandAr gument.ToS tring());
}
Then in the aspx you have:
Commandname="DoSomething" CommandArgument="22"
Or whatever you want in there then these will be available in the e object:
e.CommandArgument and e.CommandName
Ok?
You create an event handler in code behind fro the repeate like this:
MyRepeater.ItemCommand += new RepeaterCommandEventHandle
Then create an event handler like this:
public void Test(object sender, CommandEventArgs e)
{
Response.Write(e.CommandAr
}
Then in the aspx you have:
Commandname="DoSomething" CommandArgument="22"
Or whatever you want in there then these will be available in the e object:
e.CommandArgument and e.CommandName
Ok?
ASKER
I am sorry ..It is'nt clear here. Could you explain with an example..I'll give you my scenario.
I have a table called documents which has a list of filenames of the registered candidate. Now as he enters the page (i'm working on) he has to see his list of files. I am getting the files using the repeater.Now I need to link them to the prescribed location.As the button is clicked the table also needs to be updated.The table has a column called modified date. by clicking the link (for modification of the document) the date modified column must have the current date.
I have a table called documents which has a list of filenames of the registered candidate. Now as he enters the page (i'm working on) he has to see his list of files. I am getting the files using the repeater.Now I need to link them to the prescribed location.As the button is clicked the table also needs to be updated.The table has a column called modified date. by clicking the link (for modification of the document) the date modified column must have the current date.
Yes I can so that for you.
I will give you complete working code but first can you look at another question I answered for you. I thought my answer was good but you haven't assigned any points. Can you have a look at this please:
https://www.experts-exchange.com/questions/24132294/displaying-a-list-of-files-using-bulleted-list-dynamically.html
I will give you complete working code but first can you look at another question I answered for you. I thought my answer was good but you haven't assigned any points. Can you have a look at this please:
https://www.experts-exchange.com/questions/24132294/displaying-a-list-of-files-using-bulleted-list-dynamically.html
Ok thansk for the points on the other question.
Give me a little time to get this working for you - won't take too long...
Give me a little time to get this working for you - won't take too long...
What kind of files are these - ie how does the user get to them - by a url or an edit page with some kind of id on a querystring maybe?
ASKER
these files can be any document..like word or excel and it is stored in a folder called uploads under the name of the logged in user? I hope its clear .If not do let me know.
Ok that's fine
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thankyou so muuch . The code reallly worked
Of course it works, don't sound so surprised!
<asp:LinkButton ID="lnkFilename" runat="server" Text='<% # Eval("DocumentName")%>' Commandname="MyMethod" CommandArgument="<% # Eval("DocumentName")%>" ></asp:LinkButton>
Then you should be able to pick up the DocumentName in te event handler