Click here to Skip to main content
15,891,708 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
present iam developing one simple blog site.
the UI is
Date: Textbox
Message:Textbox
Keywords:Textbox
Subject:Textbox
like this.along with these controls displaying 12 buttons on behalfof 12 months,
like Jan,feb,mar,....December.
when we enter the data in controls and press submit button the data will be stored in Database.if we want to see the perticular monthof data,just press the regarding month button ,now the data of perticular month will be binded to gridview and display this gridview in next page.
i write the code for perticular month (November)
C#
protected void november_Click(object sender, EventArgs e)
{
   Response.Redirect("Messages.aspx");
}

and in Message.aspx to show the data in gridview
C#
ds = l2.nov();
g1.DataSource = ds;
g1.DataBind();


if in this condition i write the code for every month button click event in the sense the code is very huge.
is there any loop for reducing the code.if yes pls give the explanation
please give me reply to reduce the code.
Posted
Updated 24-Nov-14 21:46pm
v2

You create one parameter function where you pass Month name to function and write query based on parameter value its reduce your 12 button fuction to 1 function

ex.

Jan button

ds = l2.funcname("Jan");
g1.DataSource = ds;
g1.DataBind();

Fab button
ds = l2.funcname("Feb");
g1.DataSource = ds;
g1.DataBind();

i think it will help u
 
Share this answer
 
Comments
benzimen 25-Nov-14 7:11am    
iam very beginner.so can u pls demonistrate how to write the function?pls
Abid Shk 25-Nov-14 7:41am    
show me your ds = l2.nov(); nov funcion code here
You need to create one event handler for all "month-buttons". See: How to: Create Event Handlers in ASP.NET Web Pages[^]
 
Share this answer
 
v2
Comments
benzimen 25-Nov-14 2:17am    
even in this process also we write so much code for every event handler.
Maciej Los 25-Nov-14 2:19am    
"every event handler" - what? I'm trying to tell to use one event handler for all buttons!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900