Can't resolve for a while. Link button in a datalist
-
Read the replys :rolleyes: Pass the message ID and lookup information about the message, like username, from your datasource.
only two letters away from being an asset
-
You are right. I had a feeling that OP is absolute beginner and it would be tough for him if I suggest handling the DataList event and doing all the processing. I felt redirecting to another page would be trivial and easy for him to understand. This is the reason for that suggestion.
Navaneeth How to use google | Ask smart questions
Actually I am far from a beginner. I tried the data list handling as follows but it only gets the first row everytime, and starts over. it never goes to the next record. I know the problem but don't know the solution. What kind of template should I be using? Data List is a template. Thanks again. protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e) { foreach (DataListItem dlItem in DataList1.Items) { LinkButton lb = (LinkButton)dlItem.FindControl("deleteBtn"); using (SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString)) { sqlConnection.Open(); SqlCommand cmdRFullName = new SqlCommand("SELECT username FROM mediaComments ", sqlConnection); SqlDataReader dr = cmdRFullName.ExecuteReader(); if (dr.HasRows) { while (dr.Read()) { if (Session["user_name"] != dr["username"]) lb.Visible = false; Response.Write("dr" + dr[0] + "
"); } } } }<%# DataBinder.Eval(Container.DataItem, "commentText") %>
<%# String.Format("{0:hh}:{0:mm}{0:tt} {0:MM}.{0:dd}.{0:yy}", DataBinder.Eval(Container.DataItem, "datePosted"))%>
-
Actually I am far from a beginner. I tried the data list handling as follows but it only gets the first row everytime, and starts over. it never goes to the next record. I know the problem but don't know the solution. What kind of template should I be using? Data List is a template. Thanks again. protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e) { foreach (DataListItem dlItem in DataList1.Items) { LinkButton lb = (LinkButton)dlItem.FindControl("deleteBtn"); using (SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString)) { sqlConnection.Open(); SqlCommand cmdRFullName = new SqlCommand("SELECT username FROM mediaComments ", sqlConnection); SqlDataReader dr = cmdRFullName.ExecuteReader(); if (dr.HasRows) { while (dr.Read()) { if (Session["user_name"] != dr["username"]) lb.Visible = false; Response.Write("dr" + dr[0] + "
"); } } } }<%# DataBinder.Eval(Container.DataItem, "commentText") %>
<%# String.Format("{0:hh}:{0:mm}{0:tt} {0:MM}.{0:dd}.{0:yy}", DataBinder.Eval(Container.DataItem, "datePosted"))%>
Albert83 wrote:
Actually I am far from a beginner.
Not from your questions and responses
Albert83 wrote:
What kind of template should I be using?
See what I mean :laugh: :laugh:
Albert83 wrote:
("SELECT username FROM mediaComments ",
in-line sql, another novice mistake
Albert83 wrote:
I know the problem
So do I, it's over your head. Try looking here[^] and reading about the events, like DeleteCommand and ItemDataBound
only two letters away from being an asset
-
Albert83 wrote:
Actually I am far from a beginner.
Not from your questions and responses
Albert83 wrote:
What kind of template should I be using?
See what I mean :laugh: :laugh:
Albert83 wrote:
("SELECT username FROM mediaComments ",
in-line sql, another novice mistake
Albert83 wrote:
I know the problem
So do I, it's over your head. Try looking here[^] and reading about the events, like DeleteCommand and ItemDataBound
only two letters away from being an asset
Ok. I am not an expert but have a lot of experience. What would be a better solution to that ? "SELECT username FROM mediaComments ", in-line sql, another novice mistake I looked at ItemDataBound before (Occurs when any button is clicked in the DataList control. ) The point is not to even show the delete button for the user who is not the poster of the comment. As to templates, Repeater, and Data List can be templated. If not please explain what you mean. Thanks.
-
Ok. I am not an expert but have a lot of experience. What would be a better solution to that ? "SELECT username FROM mediaComments ", in-line sql, another novice mistake I looked at ItemDataBound before (Occurs when any button is clicked in the DataList control. ) The point is not to even show the delete button for the user who is not the poster of the comment. As to templates, Repeater, and Data List can be templated. If not please explain what you mean. Thanks.
A better solution to in-line SQL? Ever heard of stored procedures? :rolleyes:
Albert83 wrote:
I looked at ItemDataBound before (Occurs when any button is clicked in the DataList control. )
Really? Then look again "Occurs when an item is data bound to the DataList control."[^] You are using template, but using the methods incorrectly.
Albert83 wrote
"Response.Write("dr" + dr[0] + "<br />");"
; You don't need this. Use the template to show your items, that's what it there for. You should have enough information now, I suggest you read a little more and look at some of the many examples available. If you need any more, I'll have to start charging you. Where should I send the invoice?
only two letters away from being an asset
-
A better solution to in-line SQL? Ever heard of stored procedures? :rolleyes:
Albert83 wrote:
I looked at ItemDataBound before (Occurs when any button is clicked in the DataList control. )
Really? Then look again "Occurs when an item is data bound to the DataList control."[^] You are using template, but using the methods incorrectly.
Albert83 wrote
"Response.Write("dr" + dr[0] + "<br />");"
; You don't need this. Use the template to show your items, that's what it there for. You should have enough information now, I suggest you read a little more and look at some of the many examples available. If you need any more, I'll have to start charging you. Where should I send the invoice?
only two letters away from being an asset
Sure I heard of stored procedures, I use them when I find necessary. "Response.Write("dr" + dr[0] + "
");" is for testing purposes. A lot of programmers do it when testing the results of the query. All the items are templated actually. You are right i mixed it with itemCreated. Thanks for the help. -
A better solution to in-line SQL? Ever heard of stored procedures? :rolleyes:
Albert83 wrote:
I looked at ItemDataBound before (Occurs when any button is clicked in the DataList control. )
Really? Then look again "Occurs when an item is data bound to the DataList control."[^] You are using template, but using the methods incorrectly.
Albert83 wrote
"Response.Write("dr" + dr[0] + "<br />");"
; You don't need this. Use the template to show your items, that's what it there for. You should have enough information now, I suggest you read a little more and look at some of the many examples available. If you need any more, I'll have to start charging you. Where should I send the invoice?
only two letters away from being an asset
Mark Nischalke wrote:
A better solution to in-line SQL? Ever heard of stored procedures?
It's a myth. IMO, nothing wrong with inline SQL other than the difficulty of recompiling code when the DB structure changes. This can be avoided by abstracting the table structure using views. So still you can write inline SQLs safely. Please do correct me if you felt I am wrong.
Navaneeth How to use google | Ask smart questions
-
Mark Nischalke wrote:
A better solution to in-line SQL? Ever heard of stored procedures?
It's a myth. IMO, nothing wrong with inline SQL other than the difficulty of recompiling code when the DB structure changes. This can be avoided by abstracting the table structure using views. So still you can write inline SQLs safely. Please do correct me if you felt I am wrong.
Navaneeth How to use google | Ask smart questions
N a v a n e e t h wrote:
Please do correct me if you felt I am wrong.
Where do I start? This argument has been raised several times. Inline doesn't allow for separation of the business logic from the presentations, which a good design does, and increases maintenance and development. 10 apps with the same SQL statement must each be changed, rather changing one stored proc. Worse yet, if the schema changes, say a table or column is renamed, all statements must be changed instead of changing one stored proc. Inline statements also don't allow the RDBMS to optimize the execution or otherwise cache it for better performance. Just few of the many reasons. Then again, if you don't care about robust, well designed and performant applications, keep using inline statements.
only two letters away from being an asset
-
Sure I heard of stored procedures, I use them when I find necessary. "Response.Write("dr" + dr[0] + "
");" is for testing purposes. A lot of programmers do it when testing the results of the query. All the items are templated actually. You are right i mixed it with itemCreated. Thanks for the help.Albert83 wrote:
A lot of programmers do it when testing the results of the query.
:omg: :wtf: A lot of novice programmers. Professionals use a debugger.
only two letters away from being an asset
-
N a v a n e e t h wrote:
Please do correct me if you felt I am wrong.
Where do I start? This argument has been raised several times. Inline doesn't allow for separation of the business logic from the presentations, which a good design does, and increases maintenance and development. 10 apps with the same SQL statement must each be changed, rather changing one stored proc. Worse yet, if the schema changes, say a table or column is renamed, all statements must be changed instead of changing one stored proc. Inline statements also don't allow the RDBMS to optimize the execution or otherwise cache it for better performance. Just few of the many reasons. Then again, if you don't care about robust, well designed and performant applications, keep using inline statements.
only two letters away from being an asset
-
:laugh: :laugh: And if that one statement is executed 1000 times, what does that do for the performance of your system?
only two letters away from being an asset
-
:laugh: :laugh: And if that one statement is executed 1000 times, what does that do for the performance of your system?
only two letters away from being an asset
-
Albert83 wrote:
A lot of programmers do it when testing the results of the query.
:omg: :wtf: A lot of novice programmers. Professionals use a debugger.
only two letters away from being an asset