Click here to Skip to main content
15,885,869 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
hi

how to get the content of selected row value in datagridview.
Posted
Comments
Meysam Toluie 20-May-14 5:42am    
Do you need the whole row or an specific cell of it?

 
Share this answer
 
You should use OnRowCommand and use link button,

C#
protected void rowwcommandname(object sender, GridViewCommandEventArgs e)
   {
       if (e.CommandName == "name of the command")
       {
           string[] DCdata = e.CommandArgument.ToString().Split(',');
<here you="" can="" play="" with="" the="" data="">
                    
       }
   }</here>

Bind Template -----


XML
<ItemTemplate>
                                        <div style="float:left; margin:7px 0;">
                                            <asp:LinkButton ID="btnEmail" runat="server" Text="<%$Resources: Resource, btnEmail %>"
                                                CommandName="SendMail" CssClass="button" CommandArgument= '<%# Eval("DocumentCenterId") + "," + Eval("EmailId")  %>'
             meta:resourcekey="btnEmailResource1"
                                                /><div class="buttonEnding"></div>
                                                </div>
                                        </ItemTemplate>
 
Share this answer
 
Refer following code:

C#
foreach (DataGridViewRow dr in dataGridView1.SelectedRows)
            {
                foreach (DataGridViewCell dCell in dr.Cells)
                {
                   string sz= dCell.Value.ToString();
                }
            }
 
Share this answer
 
Comments
agent_kruger 28-May-14 6:41am    
sir, understand the difference between "Value" & "EdittedFormattedValue". Please see this tip/Trick for more details. http://www.codeproject.com/Tips/777492/EditedFormattedValue-v-s-Value-in-Datagridview
string sValue = string.Empty;
if (dataGridView1.CurrentCell != null && dataGridView1.CurrentCell.Value != null)
sValue = dataGridView1.CurrentCell.Value.ToString(); // Value of current cell
 
Share this answer
 
v2
Comments
agent_kruger 28-May-14 6:41am    
sir, understand the difference between "Value" & "EdittedFormattedValue". Please see this tip/Trick for more details. http://www.codeproject.com/Tips/777492/EditedFormattedValue-v-s-Value-in-Datagridview
CHill60 28-May-14 7:52am    
It's a good tip, but be aware that some members may consider posting links to your own tip like this as spam
agent_kruger 28-May-14 8:32am    
sorry sir, but to explain the difference between those 2 i have to do this.
CHill60 28-May-14 8:38am    
No you do not "have to do this" - you've written the tip that is good enough. If you start posting links to your Tip on every answer that contains .Value instead of .EditedValue then your account could well end up being suspended.
agent_kruger 28-May-14 10:20am    
sorry sir, i will not post the links again

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