How to assign to single statement [Resolved]

Posted by Oswaldlily under ASP.NET on 1/11/2012 | Points: 10 | Views : 1104 | Status : [Member] | Replies : 10
I have 10 link buttons

link1 link2 link3 link4 link5 link6 link7 link8 link9 link10

string a=this.link1.text
gridview.datasource=mapper.function(a)

string b=this.link2.text
gridview.datasource=mapper.function(b)

string c=this.link3.text
gridview.datasource=mapper.function(c)

string d=this.link4.text
gridview.datasource=mapper.function(d)

string e=this.link5.text
gridview.datasource=mapper.function(e)

string f=this.link6.text
gridview.datasource=mapper.function(f)

string g=this.link7.text
gridview.datasource=mapper.function(g)

string h=this.link8.text
gridview.datasource=mapper.function(h)

string i=this.link9.text
gridview.datasource=mapper.function(i)

string j=this.link10.text
gridview.datasource=mapper.function(j)

Is there an y possiblilities to make single assignment than writing 10 times
I expect like
string x=this.link.text (according to we click link ,it asssign text to x)

gridview.datasource=mapper.function(x)

so this x may be link1,lin2,link3,link4,link5/...........




Responses

Posted by: Sksamantaray on: 1/12/2012 [Member] Silver | Points: 50

Up
0
Down

Resolved

<asp:LinkButton ID="LinkButton1" onclick="CallMe" runat="server">LinkButton1</asp:LinkButton>

<asp:LinkButton ID="LinkButton2" onclick="CallMe" runat="server">LinkButton2</asp:LinkButton>

protected void CallMe(object sender,EventArgs e)
{
LinkButton lnkBtn=sender as LinkButton;
Response.Write(lnkBtn.Text);
//gridview.datasource=mapper.function(lnkBtn.Text.ToString.Trim()) ;
}


Hi Try This, i have removed the () from aspx page.
and let me know if it works.

Thanks,
Sanjay

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Self-innovator on: 1/11/2012 [Member] Bronze | Points: 25

Up
0
Down
You just Concatenat all the 10 link value in a single string and send this string as a parameter to sp or what ever u wanted to do....

Join Hands Change lives
Thanks & Regards
Straight Edge Society

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ogipansrk on: 1/11/2012 [Member] Starter | Points: 25

Up
0
Down
Hello,

Write an extension Method.

Ogipansrk

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 1/11/2012 [Member] Silver | Points: 25

Up
0
Down

In all LinkButton's call a single function();
like
<asp:LinkButton id="LinkButton1" onclick="CallMe()" runat="server"> Text</LinkButton>
<asp:LinkButton id="LinkButton2" onclick="CallMe()" runat="server"> Text2</LinkButton>
-- codebihind
protected void CallMe(object sender,EventArgs e)
{
LinkButton lnkBtn=sender as LinkButton;
gridview.datasource=mapper.function(lnkBtn.Text.ToString.Trim()) ;
}

Thanks,
Sanjay

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Oswaldlily on: 1/12/2012 [Member] Starter | Points: 25

Up
0
Down
@Sksamantaray

this s the error i got when i try to execute yours

Compiler Error Message: CS1061: 'ASP.fo_home_aspx' does not contain a definition for 'CallMe' and no extension method 'CallMe' accepting a first argument of type 'ASP.fo_home_aspx' could be found (are you missing a using directive or an assembly reference?)

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Oswaldlily on: 1/12/2012 [Member] Starter | Points: 25

Up
0
Down
same error repeating

CS1061: 'ASP.fo_home_aspx' does not contain a definition for 'CallMe' and no extension method 'CallMe' accepting a first argument of type 'ASP.fo_home_aspx' could be found (are you missing a using directive or an assembly reference?)

due to this page not itself getting loaded

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 1/12/2012 [Member] Silver | Points: 25

Up
0
Down


Attaching the sample project of same code.
 Download source file

Thanks,
Sanjay

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 1/12/2012 [Member] Silver | Points: 25

Up
0
Down
Its working, just download and check once and let me know.
Thanks

Thanks,
Sanjay

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Oswaldlily on: 1/12/2012 [Member] Starter | Points: 25

Up
0
Down
Yours program is correct..Now due to the follwoing error its not coming

I deleted my file and create new file of same design
still old file name is highlighting when i am redirecting and giving me error "Resources not found"

I am sure that old file not prononouncing again anywhere..How could i rectify this

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 1/12/2012 [Member] Silver | Points: 25

Up
0
Down
delete everything from :
C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files
folder and then try.


Thanks,
Sanjay

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response